xxxxxxxxxx
149
let x;
let y;
let easing;
let balls;
let myBall;
let globalTargX;
let globalTargY;
let center;
let cloudSize;
function setup() {
noStroke();
center = false;
cloudSize = 60;
// globalTargX = width/2;
// globalTargY = height/2;
createCanvas(400, 400);
x = 0;
y = 0;
easing = 0.06;
balls = [];
for (let i = 0; i < 10; i++) {
let rx = random(0, width);
let ry = random(0, height);
let rEase = random(0.001, 0.05);
let rSize = random(3, 6);
balls.push(new Ball(rx, ry, rEase, rSize));
}
}
function draw() {
background(220);
setTarg();
for (let i = 0; i < balls.length; i++) {
balls[i].go();
}
if (center) {
for (let i = 0; i < balls.length; i++) {
balls[i].targX = mouseX;
balls[i].targY = mouseY;
//balls[i].easing = 0.001;
//balls[i].easing = random(0.0002,0.002);
}
}
}
// let targX = mouseX;
// let dx = targX - x;
// x += dx *easing
// let targY = mouseY;
// let dy = targY - y;
// y += dy *easing
// ellipse(x,y,50,50);
function Ball(tx, ty, tEase, tSize) {
this.x = tx;
this.y = ty;
this.easing = tEase;
this.size = tSize;
this.targX = random(width);
this.targY = random(height);
this.repicked = true;
this.pickVal = function(){
this.targX = random(mouseX -cloudSize, mouseX + cloudSize);
this.targY = random(mouseY -cloudSize, mouseY + cloudSize);
this.repicked = true;
}
this.go = function() {
// fill(0);
// ellipse(width/2,height/2,100,100);
this.easing *= random(1.1,1.6);
if (this.easing > .3) {
this.easing = 1;
}
//this.targX += random(-.10,.10);
//this.targY += random(-.10,.10);
// if(this.y == this.targY && !this.repicked)
// {
// this.targY = random(width);
// this.repicked = true;
// }
//this.targX = globalTargX;
this.dx = this.targX - this.x;
this.x += this.dx * this.easing;
//this.targY = globalTargY;
this.dy = this.targY - this.y;
this.y += this.dy * this.easing;
colorMode(HSB);
fill(0,60,60);
ellipse(this.x, this.y, this.size, this.size);
if(this.x == this.targX && this.y == this.targY &&this.repicked)
{
this.easing = random(0.04, 0.08);
this.pickVal();
}
}
}
function setTarg() {
if (center) {
globalTargX = mouseX;
globalTargY = mouseY;
}
}