xxxxxxxxxx
88
var img;
var balls = [];
function preload() {
img = loadImage("logo1080.png");
}
function setup() {
createCanvas(img.width, img.height);
background(255);
textAlign(CENTER);
}
function draw() {
// clear();
for (var i = 0; i < balls.length; i++) {
balls[i].draw();
balls[i].update();
balls[i].changeColour();
}
for (var i = 0; i < balls.length; i++) {
if (balls[i].life == 0) {
balls.splice(i, 1);
} else {
balls[i].life--;
}
}
for (var i = 0; i < 10; i++) {
let x = random(width);
let y = random(height);
balls.push(new Ball(x, y, color(img.get(x, y))));
}
}
class Ball {
constructor(mX, mY, c) {
this.speed = 0.01;
this.location = createVector(mX, mY);
this.v = createVector(
random(-this.speed, this.speed),
random(-this.speed, this.speed)
);
this.radius = random(10);
this.r = red(c);
this.g = green(c);
this.b = blue(c);
this.life = parseInt(random(100, 255));
this.xOff = 0.0;
this.yOff = 0.0;
}
update() {
this.xOff += this.v.x;
this.nX = this.xOff;
this.yOff += this.v.y;
this.nY = this.yOff;
this.location.x += this.nX;
this.location.y += this.nY;
}
changeColour() {
this.c = color(img.get(this.location.x, this.location.y));
this.r = red(this.c);
this.g = green(this.c);
this.b = blue(this.c);
}
draw() {
noFill();
stroke(this.r, this.g, this.b, 10);
point(this.location.x, this.location.y);
}
}
function keyPressed()
{
save("output.png");
}