//////Interactive Toy - AESTHETIC DISCO BALL - by Liz Zhang////// ///This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. ////////http://creativecommons.org/licenses/by-sa/3.0/deed.en_US void setup() { size(400, 800); frameRate(60); xx=300; yy=50; ballXSpeed=1; ballYSpeed=1; } void draw() { //////Setting up the background// Making an aesthetically pleasing coral toned gradient noStroke(); fill(255,240,237); rectMode(CORNERS); rect(0,750,400,800); noStroke(); fill(255,225,219); rectMode(CORNERS); rect(0,700,400,750); noStroke(); fill(255,212,203); rectMode(CORNERS); rect(0,650,400,700); noStroke(); fill(255,193,180); rectMode(CORNERS); rect(0,600,400,650); noStroke(); fill(255,173,157); rectMode(CORNERS); rect(0,550,400,600); noStroke(); fill(255,163,144); rectMode(CORNERS); rect(0,500,400,550); noStroke(); fill(255,150,129); rectMode(CORNERS); rect(0,450,400,500); noStroke(); fill(255,139,116); rectMode(CORNERS); rect(0,400,400,450); noStroke(); fill(255,126,100); rectMode(CORNERS); rect(0,350,400,400); noStroke(); fill(255,116,88); rectMode(CORNERS); rect(0,300,400,350); noStroke(); fill(255,105,75); rectMode(CORNERS); rect(0,250,400,300); noStroke(); fill(255,97,62); rectMode(CORNERS); rect(0,200,400,250); noStroke(); fill(255,94,62); rectMode(CORNERS); rect(0,150,400,200); noStroke(); fill(255,83,49); rectMode(CORNERS); rect(0,100,400,150); noStroke(); fill(255,77,41); rectMode(CORNERS); rect(0,50,400,100); noStroke(); fill(255,60,21); rectMode(CORNERS); rect(0,0,400,50); /////////////// Disco Ball /////////// //////////// Making the ball and it's random colour flashing ////////// r=random(0, 255); g=random(100, 255); b=random(50, 200); fill(r, g, b); ellipseMode(CENTER); ellipse(xx, yy, 100,100); //////// Keep the ball from bouncing out of bounds if (xx>width-12) { ballXSpeed = ballXSpeed * -.5; xx=width-12; } else if (xx<12) { ballXSpeed = ballXSpeed * -.5; xx=12; } if (yy>height-12) { ballYSpeed = ballYSpeed * -.9; yy=height-12; } //////// Add speed to the ball yy = yy + ballYSpeed; xx = xx + ballXSpeed; ////// Gravity increases with the speed of the ball ballYSpeed = ballYSpeed + gravity; //////// Make sure the ball will always bounce if (yy > height) { ballYSpeed = ballYSpeed * -0.30; yy = constrain(yy, 0, 800); xx = constrain(xx, 0, 800); } ///////////Ball follows mouse when pressed with acceleration if (mousePressed) { ballYSpeed+=-.08; if (mouseX>xx) { ballXSpeed+=.05; } else if (mouseX<xx) { ballXSpeed+=-.05; } } } ///// locations and speed of the ball at these locations float xx = 300; float yy = 0; float ballXSpeed; float ballYSpeed; float r; float g; float b; float gravity = 0.25;