Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
Add Comment
Please, Sign In to add comment