xxxxxxxxxx
55
//How do I convert Cluster into a class to make multiple clusters?
//I would also need to make a Dot class to govern the dots inside the cluster.
let offsetX = [3, -5, 8, -13, 21, -10]
let offsetY = [34, -21, 13, -8, 5, 3]
let rand;
let cluster1, cluster2, cluster3;
let dot = {
x: 100,
y: 100,
dia: 5,
spacing: 10,
rand: 0
}
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
cluster1 = new Cluster();
cluster2 = new Cluster();
cluster3 = new Cluster();
}
function draw() {
background(220);
dot.x = mouseX - 50;
dot.y = mouseY - 50;
dot.rand = random(-0.5, 0.5);
cluster1.make();
cluster2.make();
cluster3.make();
}
class Cluster {
constructor() {
}
make() {
for (let i = 0; i < 6; i++) {
fill(0);
ellipse((dot.x + (offsetX[i] / 2) + dot.rand), (dot.y - (offsetY[i]) / 2) + dot.rand, dot.dia);
}
}
}