xxxxxxxxxx
85
let balls;
class ball {
constructor(x,y,vx,vy,color,size,dir,shadow) {
this.position = createVector(x,y);
this.oposition = createVector(x,y);
this.velo = createVector(vx,vy);
this.color = color;
this.size = size;
this.origsize = size;
this.dir = dir;
this.shadow = shadow;
}
update() {
this.position.x += this.velo.x;
this.position.y += this.velo.y;
this.size += 0.5;
if (this.position.x > width+this.size/2 || this.position.y > height+this.size/2) {
this.position = this.oposition;
this.size = this.origsize;
}
}
draw() {
drawShadow(500);
fill(this.color);
noStroke();
circle(this.position.x,this.position.y,this.size);
fill(0);
drawShadow(this.shadow);
circle(this.position.x,this.position.y,this.size/2);
circle(this.position.x,this.position.y,this.size/4);
circle(this.position.x,this.position.y,this.size/8);
circle(this.position.x,this.position.y,this.size/16);
}
}
function drawShadow(b) {
drawingContext.shadowOffsetX = 2;
drawingContext.shadowOffsetY = 2;
drawingContext.shadowBlur = b;
drawingContext.shadowColor = color(180); //"black";
}
// let gfx;
function setup() {
// let size = 10;
balls = [];
createCanvas(800,800);
// gfx = createGraphics(width,height);
for (let i = 0; i < 10; i++) {
let size = random(5,25);
balls.push(new ball(
random(-500,-size),height/2,
random(0.5,3.0), 0,
color(0), size,
true,
random(0.5,3)
));
balls.push(new ball(
width/2,random(-500,-size),
0, random(0.5,3.0),
color(0), size,
false,
random(0.5,3)
));
}
}
function draw() {
background(220);
for (let i = balls.length-1; i >= 0; i--) {
balls[i].update();
balls[i].draw();
}
// image(gfx,0,0);
}