Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var amount=10;
- var growfactor=1.01;
- var person= [];
- class Bubble{
- constructor() {
- this.x=random(width);
- this.y=random(height);
- this.vx=random(-10,10);
- this.vy=random(-10,10);
- }
- move(){
- this.x=this.x+this.vx;
- this.y=this.y+this.vy;
- }
- checkbounce(){
- if(this.x>width || this.x<0){
- this.vx=this.vx*-1
- this.vx=this.vx*growfactor;
- }
- if(this.y>width || this.y<0){
- this.vy=this.vy*-1
- this.vy=this.vy*growfactor;
- }
- }
- show(){
- stroke(255)
- noFill()
- ellipse(this.x,this.y,10,10)
- }
- }
- function setup() {
- createCanvas(400, 400);
- for(var i=0;i<amount;i++){
- person[i]= new Bubble();
- }
- }
- function draw() {
- background(0);
- for(var i=0;i<amount;i++){
- person[i].move();
- person[i].checkbounce();
- person[i].show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment