xxxxxxxxxx
61
//Position
var x,y;
//Switch Button
var button = false;
function setup() {
createCanvas(windowWidth, windowHeight);
x = random(0, width);
y = height;
//Introduction Text
fill(255, 255, 0);
textAlign(CENTER);
textSize(32);
text('Double click to start and double click to freeze.', width/2, 30);
noCursor();
}
function draw() {
//Ball Color
var r = map(mouseY, 0, height, 0, 255);
var g = map(mouseX, 0, width, 0, 255);
var b = map(mouseY, 0, height, 0, 255);
noStroke();
//Switch On
if (button) {
background(0,0,0,10);
fill(r, g, 255-b);
ellipse(x, y, 30, 30);
// Jiggling randomly on the horizontal axis
x = x + random(-1, 1);
// Moving up at a constant speed
if (y > 0) {
y = y - 1;
} else {
y = height;
}
}
}
//Switch Off
function doubleClicked() {
button = !button;
}