Command+Shift+F: tidy your code
define function: setup() (Can do this)
setup();
call function: (Do this)
x = x + 10
//equals to
var on = false;
if(!on)
//!on = Not False = True
//This code does get evaluated
on = !on
//similar to speed = speed*-1
//true becomes not true(false) and vice versa
//Initial
funstion mousePressed() {
if (mouseX > 250)
if (on) {
on = false;
} else {
on = true;
}
}
}
//change into this
funstion mousePressed() {
if (mouseX > 250)
on = !on;
}
}
function setup() {
createCanvas(480, 120);
}
function draw() {
background(204);
line(0, 0, width, height);
// Line from (0,0) to (480, 120) line(width, 0, 0, height);
line(width, 0, 0, height);
// Line from (480, 0) to (0, 120)
Operators:
456*3 //Expressions
var x = 4 + 4 * 5; // Assign 24 to x
var x = (4 + 4) * 5; // Assign 40 to x
x += 10; // This is the same as x = x + 10
y −= 15; // This is the same as y = y - 15
x++; // This is the same as x = x + 1
y−−; // This is the same as y = y − 1