Click and drag to draw. Press 'c' to change color, press 'b' to change brush. Press 'p' to download your image.
xxxxxxxxxx
let clr = [];
let i = 0;
let f = 0;
brush = 1;
let drawing;
function setup() {
drawing = createCanvas(400, 400);
background(220);
clr = [255, color(255, 0, 0), color(0, 255, 0), color(0, 0, 255), 0];
f = clr[i];
}
function draw() {
fill(f);
if(mouseIsPressed){
if(brush == 1){
stroke(f);
circle(mouseX,mouseY, 30);
}
if(brush == 2){
stroke(f)
rect(mouseX,mouseY, 30);
}
if(brush == 3){
stroke(f);
line(mouseX, mouseY, pmouseX, pmouseY);
}
}
}
function keyPressed(){
if(keyCode == SHIFT){
background(random(0,255),random(0,255), random(0,255));
}
if(keyCode == RETURN){
background(220);
}
if(key == 'c'){
i++;
}
if(key == 'b'){
brush++;
}
if(brush>3){
brush = 1;
}
if(i > 4){
i = 0;
}
f = clr[i];
if(key == 'p'){
saveCanvas(drawing, 'myDrawing', 'jpg');
}
}