Para este boceto, quería que las estrellas tuvieran colores ligeramente diferentes, para emular cómo las estrellas reales no son solo luz blanca pura. Probé algunos métodos diferentes para hacer esto sin ningún éxito. ¿Cómo lograrías esto?
Buscando modificar el primer fill(255) para dibujar cada estrella en un color distinto de un conjunto. Intenté usar una matriz de alrededor de 4 colores y acceder a los índices. Intenté usar random() para elegir valores rgb a unos pocos números de 255. Soy bastante nuevo en esto, así que perdone mi falta de terminología adecuada. Creo que probablemente no puse mi bucle a través de las matrices en el lugar correcto.
El código completo está aquí . ¡Gracias por adelantado!
function starsMoon() { //create star cluster and moon randomSeed(300); translate(-width * 2, -height * 2); noStroke(); fill(255); for (let i = 0; i < 300; i++) { // stars // this is where I initially put the fill(colorSet[i]) ellipse(random(0,width * 4) + i, random(0,height * 4) + i, 2, 2); } fill(255); ellipse(width * 1.25, height * 2, 100, 100); // moon }Sí, ¡cualquiera de los dos funcionaría!
Compensación aleatoria:
function starsMoon() { //create star cluster and moon randomSeed(300); translate(-width * 2, -height * 2); noStroke(); for (let i = 0; i < 300; i++) { // stars fill(250 + ((random() - 0.5) * 2 * 5)) // random fill between 245 - 255 ellipse(random(0,width * 4) + i, random(0,height * 4) + i, 2, 2); } fill(255); ellipse(width * 1.25, height * 2, 100, 100); // moon }Para rotar a través de los colores de una lista, solo necesita tomar el índice mod el número de colores:
function starsMoon() { //create star cluster and moon randomSeed(300); translate(-width * 2, -height * 2); noStroke(); let colors = [ color(210, 180, 170), color(40, 100, 29), color(100, 100, 110), color(102, 210, 12) ] for (let i = 0; i < 300; i++) { // stars fill(colors[i % colors.length]) // loop through colors ellipse(random(0,width * 4) + i, random(0,height * 4) + i, 2, 2); } fill(255); ellipse(width * 1.25, height * 2, 100, 100); // moon }Genial proyecto por cierto!