xxxxxxxxxx
46
//brush control variables
var RANDCIRC = false; //enabled/disabled with 'c' key
function setup() {
createCanvas(500, 500);
background(255);
noStroke();
}
function draw() {
//not drawing a background every frame because we want
//it to be treated like a piece of canvas that we are adding shapes to
//if the RANDCIRC brush is enabled (RANDCIRC == true)
if (RANDCIRC == true) {
//set a random fill color that is mostly transparent
fill(random(150, 200), random(150, 200), random(150, 200), 10);
//draw a circle at the current mouse position
//draw it larger if the mouse is held down than if it isn't
if (mouseIsPressed) {
ellipse(mouseX, mouseY, 200, 200);
} else {
ellipse(mouseX, mouseY, 100, 100);
}
}
}
//code inside the keyPressed function runs whenever a key is pressed
function keyPressed() {
//'c' is the toggle for the first brush, RANDCIRC
if (key == "c") {
RANDCIRC = !RANDCIRC; //! negates the value, so T -> F; F -> T
}
//clear the screen with the 'r' key
if (key == "r") {
background(255);
}
//save the sketch with the 's' key
if (key == "s") {
save("output.png");
}
}