xxxxxxxxxx
56
var circles= []
var screenWidth;
var screenHeight;
function setup() {
screenWidth = 150;
screenHeight = 250;
createCanvas(screenWidth, screenHeight);
background(0);
for (i = 0; i < 10; i++) {
if (i < 2) {
let circle = new Circle(1);
circles.push(circle);
}
else {
let circle = new Circle(0);
circles.push(circle);
}
}
noStroke();
fill(255,255,255,100);
}
function draw() {
background(0);
for (i = 0; i < 5; i++) {
circles[i].update();
circles[i].display();
}
}
class Circle {
constructor(x) {
this.size = random(50,100);
if (x == 1) {
this.x = 0-this.size/2;
}
else {
this.x = 0-random(this.size/2,screenWidth);
}
this.y = random(screenHeight);
}
display() {
ellipse(this.x,this.y,this.size)
}
update() {
if (this.x>screenWidth+this.size/2) {
this.x = 0-this.size/2;
this.y=random(screenHeight);
}
this.x += random(0.1,0.5);
// this.x+=10;
}
}