Skip to content

Instantly share code, notes, and snippets.

@ulrichzwingli
Last active October 16, 2017 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulrichzwingli/82ba868ef1aac15596b0a0a3191322d2 to your computer and use it in GitHub Desktop.
Save ulrichzwingli/82ba868ef1aac15596b0a0a3191322d2 to your computer and use it in GitHub Desktop.
Dancing_Falling_Balls_Gravity
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