xxxxxxxxxx
123
var x;
var y;
var speed;
var velocity;
var padding;
var myCircs = [];
var tempColor;
var howMany;
function setup() {
colorMode(RGB);
createCanvas(600,600);
howMany = 20;
for(let i=0; i < howMany; i++){
let rY = random(0,height);
let rSpeed = random(1,4);
let rVel = random(1,3);
let rPad = random(10,50);
let rSize = random(10,50);
// let fr = random(0,255);
// let fg = random(0,255);
// let fb = random(0,255);
myCircs.push(new Circ(0,rY,rSpeed,rVel,rPad,rSize));//,rr,rg,rb));
myCircs[i].x = random(20,80);
}
createCanvas(400, 400);
padding = 50;
x = padding;
y = height / 2;
speed = 1;
velocity = 0.7;
noStroke();
//tempColor = color(255,70,0);
myCirc = new Circ(1, 1, 20, 20);
}
function draw() {
background(255);
myCirc.display();
myCirc.move();
for(let i=0; i < howMany; i++){
myCircs[i].display(255,0,0);
myCircs[i].move();
}
}
function Circ(tempX, tempY, tempSpeed, tempVel, tempPadding, tempSize)//, tr,tg,tb) //, tempC )
{
this.speed = tempSpeed;
this.velocity = tempVel;
this.padding = tempPadding;
this.size = tempSize;
//this.myC = color(0,0,0);
//this.myC = tempC;
this.x = tempX;
this.y = tempY; //.random(0,height);
// this.r=tr;
// this.g=tg;
// this.b=tb;
this.display = function(fr,fg,fb) {
//fill(this.myC);
//fill(this.r,this.g,this.b);
//fill(fr,fg,fb);
fill(100);
ellipse(this.x, this.y, this.size);
}
this.move = function() {
this.x += this.speed;
this.speed += this.velocity;
if (this.x > width - this.padding) {
this.speed = -1;
this.velocity *= -1;
}
if (this.x < this.padding) {
this.speed = 1;
this.velocity *= -1;
}
}
}