Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
¿Cómo recorrer el conjunto de colores y aplicar para "rellenar" en p5.js?

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 }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!