mouse move to erase, c to renew, n&m change color, click for triangles, click right and left
xxxxxxxxxx
/*react in some way to the mouse.
be able to be cleared (completely erased) to start over.
use randomness in some cool way. */
var color1 = "red";
var color2 = "yellow";
var color3 = "blue";
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
frameRate(20);
}
function draw() {
//to erase the color on canvas
var speed = dist(mouseX, mouseY, pmouseX, pmouseY);
fill(255);
noStroke();
ellipse(mouseX, mouseY, speed, speed);
//Mondrian random coloring
var gridsize = 40;
var whichcolor = floor(random(3)); // floor() hacks off the decimal point
if(whichcolor==0) fill(color1);
if(whichcolor==1) fill(color2);
if(whichcolor==2) fill(color3);
stroke(0);
var x = random(width);
var y = random(height);
x = ceil(x/gridsize)*gridsize;
y = ceil(y/gridsize)*gridsize;
var w = ceil(random(2))*gridsize;
var h = ceil(random(2))*gridsize;
rect(x, y, w, h);
//Pollock triangles
var x1 = random(width);
var y1 = random(height);
var x2 = random(width);
var y2 = random(height);
noFill() ;
stroke(0);
if(mouseIsPressed) triangle(x1, y1, x2, y2, mouseX, mouseY);
// get impressed from here
// https://p5js.org/reference/#/p5/mouseButton
fill(0);
if (mouseIsPressed) {
if (mouseButton === LEFT) {
ellipse(mouseX, mouseY, 50, 50);
}
if (mouseButton === RIGHT) {
rect(mouseX, mouseY, 50, 50);
}
}
}
function keyTyped() {
if(key=='c') background(255); //renew
if(key=='m') { //Mondrian color
color1 = "red";
color2 = "yellow";
color3 = "blue";
}
if(key=='n') { //New color
color1 = "MistyRose";
color2 = "LightBlue";
color3 = "LemonChiffon";
}
}