xxxxxxxxxx
38
/*
* Demonstrates an if... else if... else... statement
* with use of &&, or ||
*/
var rectX = 0;
function setup() {
createCanvas(600, 600);
colorMode(HSB, 360, 100, 100);
background(0,0,0);
noStroke();
}
function draw() {
background(0,0,0);
// Select hue based on position of rectangle and mouse
// Try swapping && for ||
if (rectX < width/3 && mouseX > width/2){
fill(0, 80,100);
}
else if (rectX < (width / 1.5)){
fill(135, 80,100);
}
else{
fill(225, 80,100);
}
rect(rectX,200,100,100);
rectX += 6;
// Loop around
if(rectX > width){
rectX = -100;
}
}