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);
}