Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

294
Vistas
Why the array not work in p5.js in storing colors

It is a painting apps for users to select colors and brushes to draw on the canvas. I used the array to store the color code but it cannot work. I have four colors in the code and I want it refers to each color for the brush to paint. Hope someone can help me, thank you!

var brushColor;
let slider;
let strokeType
let x = 10;
let y = 50;

function setup() {
  createCanvas(500, 500);
  brushColor = color(50);
  strokeType = ROUND;
}

function draw() {
  if (mouseIsPressed) {
    if (mouseX <= 50) {
      if (mouseY <= 50) {
        brushColor = colors[1];
      } else if (mouseY <= 100) {
        brushColor = color[2];
      } else if (mouseY <= 150) {
        brushColor = color[3];
      } else if (mouseY <= 200) {
        brushColor = color[4];
      } else if (mouseY <= 450) {
        strokeType = PROJECT;
      } else if (mouseY <= 500) {
        strokeType = ROUND;
      }
    }
  }

  stroke(color(0));
  fill(colors[1]);
  rect(0, 0, 50, 50);
  fill(colors[2]);
  rect(0, 50, 50, 50);
  fill(colors[3]);
  rect(0, 100, 50, 50);
  fill(colors[4]);

  rect(0, 300, 50, 50);
  print(brushColor)
  fill(220);

  fill(255);
  rect(0, 400, 80, 50)
  fill(255);
  rect(0, 450, 80, 50)
  stroke(1);
  fill(brushColor);
  rect(26.5, 413.5, 25, 25)
  ellipse(40, 475, 25, 25)
  print(brushColor);
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda