Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda