Press r, g, b, y, w or v to change the brush color. Press 1, 2, or 3 to change the brush shape. Press c to clear the canvas with the original background color, Press n to change the background color to black. Press p to print your design.
xxxxxxxxxx
let brushColor
let brush = 1
function setup() {
createCanvas(400, 400);
background(220);
brushColor = color(255)
}
function draw() {
// let brushColor = color(255)
if (mouseIsPressed && brush == 1){
noStroke()
fill(brushColor)
ellipse(mouseX,mouseY,20,20)
}
if (mouseIsPressed && brush == 2){
noStroke()
fill(brushColor)
square(mouseX,mouseY,20)
}
if (mouseIsPressed && brush == 3){
noStroke()
fill(brushColor)
triangle(mouseX,mouseY-20,mouseX +20,mouseY +10,mouseX-20,mouseY+10)
}
}
function keyPressed(){
if (key == 'c'){
background(220)
}
if (key == 'n'){
background(0)
}
if (key == 'r'){
brushColor = color(255,0,0)
}
if (key == 'g'){
brushColor = color(0,255,0)
}
if (key == 'b'){
brushColor = color(0,0,255)
}
if (key == 'y'){
brushColor = color(255,255,0)
}
if (key == 'v'){
brushColor = color(160,0,160)
}
if (key == 'w'){
brushColor = color(255)
}
if (key == '1'){
brush = 1
}
if (key == '2'){
brush = 2
}
if (key == '3'){
brush = 3
}
if(key == 'p')
{
print()
}
}