xxxxxxxxxx
// this is a comment
// control-shift J appears to open the developer console
// these variables are GLOBAL (variable scope):
var color0 = "black"; // edge color
var color1 = "red";
var color2 = "yellow";
var color3 = "blue";
var bmodes = [];
var b = 0;
// setup runs once when you hit play!
function setup() {
createCanvas(windowWidth, windowHeight); // this is saying how big our canvas is
background(255); // this is our background color
rectMode(CENTER); // rectangles will draw on center
// BLEND, DARKEST, LIGHTEST,
// DIFFERENCE, MULTIPLY, EXCLUSION,
// SCREEN, REPLACE, OVERLAY,
// HARD_LIGHT, SOFT_LIGHT, DODGE,
// BURN, ADD, REMOVE or SUBTRACT
bmodes = [BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN, ADD, REMOVE, SUBTRACT];
blendMode(bmodes[b]);
}
// draw runs every frame over and over and over and over and over
function draw() {
// these variables are local:
var gridsize = 50; // how wide is the grid in pixels
// random makes random numbers: one argument is a range, two args are a min and a max
stroke(color0);
strokeWeight(random(2, 10)); // this will make a thicker line
var whichcolor = floor(random(3)); // floor() hacks off the decimal point
//console.log(whichcolor);
if(whichcolor==0) fill(color1);
if(whichcolor==1) fill(color2);
if(whichcolor==2) fill(color3);
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); // draw a rectangle - arguments are x, y, width, height
}
function keyTyped() // this runs when i type a key on the keyboard
{
if(key=='q') { // classic mondrian
color0 = "black";
color1 = "red";
color2 = "yellow";
color3 = "blue";
}
if(key=='w') {
color0 = "Firebrick";
color1 = "SlateBlue";
color2 = "PeachPuff";
color3 = "Aqua";
}
if(key=='c') background(255);
console.log("i typed something: " + key); // 'key' is which key you type
background(255);
b = (b+1)%bmodes.length;
blendMode(bmodes[b]);
}