Last active
October 16, 2017 17:47
-
-
Save ulrichzwingli/82ba868ef1aac15596b0a0a3191322d2 to your computer and use it in GitHub Desktop.
Dancing_Falling_Balls_Gravity
This file contains 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 acc, vel, xpos, ypos; | |
var balls= []; | |
function setup() { | |
createCanvas(400, 400); | |
//for(i=0;i<10;i++){ | |
// balls[i] = new Balls; | |
} | |
function mouseDragged(){ | |
balls.push(new Balls(mouseX,mouseY)); | |
} | |
function draw() { | |
background(0); | |
for(i=0;i<balls.length;i++){ | |
balls[i].displ(); | |
balls[i].bounce(); | |
} | |
} | |
function Balls(x,y) { | |
this.xpos = x; | |
this.ypos = y; | |
this.acc = 0.1; | |
this.vel = 0; | |
this.displ= function(){ | |
fill(255,random(0,255),random(0,255),100); | |
ellipse(this.xpos,this.ypos,25,25); | |
}; | |
this.bounce = function() { | |
this.ypos += this.vel; | |
this.vel += this.acc; | |
if(this.ypos>400){ | |
this.vel*= -0.9; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment