xxxxxxxxxx
80
class Spot {
constructor(_x, _y, _c, _r) {
this.x = this.x_init = _x;
this.y = this.y_init = _y;
this.c = _c;
this.r = _r;
this.param_noise = random(10000.0);
this.position_noise_x = random(10000.0);
this.position_noise_y = random(10000.0);
this.increment_noise = 0.01;
this.increment_noise_position = 0.001;
}
draw() {
this.param_noise = this.param_noise + this.increment_noise;
this.position_noise_x += this.increment_noise_position;
this.position_noise_y += this.increment_noise_position;
this.x = this.x_init + 100 * noise(this.position_noise_x);
this.y = this.y_init + 100 * noise(this.position_noise_y);
noStroke();
fill(this.c);
beginShape();
for (var angle = 0.0; angle < 360.0; angle = angle + 1.0) {
var circle_noise = 20 * noise(
this.param_noise + cos(radians(angle)),
this.param_noise + sin(radians(angle))
);
vertex(
this.x + (this.r + circle_noise) * cos(radians(angle)),
this.y + (this.r + circle_noise) * sin(radians(angle)));
}
endShape();
}
}
class SunnyCandy {
constructor(_n, _r_min, _r_max) {
var c = [
[255,0,0, 150],
[0,255,0, 150],
[0,0,255, 150],
[255,0,255, 150],
[0,255,255, 150]
];
this.spot = new Array(_n);
for (let i = 0; i < this.spot.length; i++) {
this.spot[i] = new Spot(random(width), random(height), c[parseInt(random(c.length))], random(_r_min, _r_max));
}
}
draw() {
background(255);
for (let i = 0; i < this.spot.length; i++) {
this.spot[i].draw();
}
}
}
var sunny_candy;
function setup() {
frameRate(30);
createCanvas(windowWidth, windowHeight);
sunny_candy = new SunnyCandy(10, 5, 40);
}
function draw() {
sunny_candy.draw();
fill(0);
text(frameRate(), 10, 10);
}
function keyPressed()
{
if( key == 's' ){
save("output.png");
}
}