Created
November 9, 2016 16:57
-
-
Save jayaprasad37/eec6abba284883a19bcd80f157ae25a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var bubbles = []; | |
| function setup() { | |
| createCanvas(800, 600); | |
| for(var i=0; i<0; ++i) | |
| { | |
| bubbles[i] = new Bubble(random(750), random(550)); | |
| } | |
| } | |
| function draw() { | |
| background(0); | |
| for(var i = 0; i <bubbles.length; ++i) | |
| { | |
| bubbles[i].display(); | |
| bubbles[i].move(); | |
| bubbles[i].bounce(); | |
| if(bubbles[i].x > width - 50 || bubbles[i].x < 50 || bubbles[i].y > height - 50 || bubbles[i].y < 50) | |
| { | |
| bubbles.splice(i, 1); | |
| } | |
| } | |
| if(bubbles.length > 50) | |
| { | |
| bubbles.splice(0,1); | |
| } | |
| if(mouseIsPressed) | |
| { | |
| bubbles.push(new Bubble(mouseX, mouseY)); | |
| } | |
| } | |
| function mousePressed() | |
| { | |
| bubbles.push(new Bubble(mouseX, mouseY)); | |
| } | |
| function Bubble( x, y) { | |
| this.x = x; | |
| this.y = y; | |
| this.xspeed = random(-1,1); | |
| this.yspeed = random(-1,1); | |
| this.r = random(255); | |
| this.g = random(255); | |
| this.b = random(255); | |
| this.display = function () | |
| { | |
| stroke(255); | |
| strokeWeight(10); | |
| fill(this.r, this.g, this.b, 180 ); | |
| ellipse(this.x, this.y , 100, 100); | |
| } | |
| this.move = function() | |
| { | |
| this.x =(this.x+this.xspeed); | |
| this.y =(this.y+this.yspeed); | |
| } | |
| this.bounce = function() | |
| { | |
| if(this.x >width - 50 || this.x < 50 ) | |
| { | |
| this.xspeed = -this.xspeed; | |
| } | |
| if(this.y > height - 50 || this.y <50) | |
| { | |
| this.yspeed = -this.yspeed; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment