xxxxxxxxxx
83
let Forms = []; //where we store all the Form objects
var a = 0;
var b = 0;
var c = 0;
var r = 10;
function setup() {
createCanvas(600, 600);
a = random(150, 255);
b = random(250, 255);
c = random(150, 255);
rectMode(CENTER);
}
function mouseDragged() {
//Random value for "radius"
var chance = random(50);
if (chance <= 3) {
r += random(-3,5)
let b = new Form(mouseX, mouseY, r);
Forms.push(b); //push to list
b.randomize(); //randomize the colors
} else {
}
}
function draw() {
background(0);
for (let Form of Forms) {
Form.move();
Form.create();
}
for (let i = 0; i < Forms.length; i++) {
Forms[i].move();
Forms[i].create();
}
}
class Form {
constructor(x, y, r) {
this.x = x;
this.y = y;
this.r = r;
}
move() {
if (mouseX >= this.x) {
this.x = this.x + random(5);
} else {
this.x = this.x + random(-5);
}
if (mouseY >= this.y) {
this.y = this.y + random(10);
} else {
this.y = this.y + random(-10);
}
//vibration. Can also use perlin noise.
}
randomize() {
a = random(150, 255);
b = random(250, 255);
c = random(150, 255);
}
create() {
//create random figures
var p = random(200);
//1/20 for cirlce
if (p <= 70) {
//circle
stroke(a, b, c);
strokeWeight(4);
noFill();
ellipse(this.x, this.y, this.r * 2);
}
}
}