xxxxxxxxxx
87
//Set n to whatever number you want!
let n = 1;
let patterns = [];
function setup() {
createCanvas(400, 400);
for (i = 0; i < n; i += 1) {
let length = 25 + i * 10
patterns[i] = new Spinner(length);
}
}
function draw() {
background(0);
for (i = 0; i < patterns.length; i += 1) {
patterns[i].position();
patterns[i].spin();
//patterns[i].colorGrowth();
}
}
class Spinner {
constructor(r) {
this.x = 200;
this.y = 200;
this.r = r;
this.t1 = 0;
this.t2 = PI + this.t1;
this.speed = 0.015;
/*
this.red = 150;
this.green = 150;
this.blue = 255
this.colorIncrementRed = -1
this.colorIncrementGreen = 1
this.colorIncrementBlue = 1
*/
}
spin() {
let increase = random(0, this.speed)
this.t1 += increase;
this.t2 -= increase;
}
/*
colorGrowth() {
if (this.red == 255 || this.red == 0) {
this.colorIncrementRed = - this.colorIncrementRed
}
this.red += this.colorIncrementRed;
if (this.green == 255 || this.green == 0) {
this.colorIncrementGreen = - this.colorIncrementGreen
}
this.green += this.colorIncrementGreen;
if (this.blue == 255 || this.blue == 0) {
this.colorIncrementBlue = - this.colorIncrementBlue
}
this.red += this.colorIncrementBlue;
}
*/
position() {
stroke(random(0,255),random(0,255),random(0,255));
strokeWeight(5);
for (let i = 0; i < 8; i++) {
let thetaIncrease = i * QUARTER_PI
let x1 = this.x + this.r * cos(this.t1 + thetaIncrease);
let y1 = this.y + this.r * sin(this.t1 + thetaIncrease);
let x2 = this.x + this.r * cos(this.t2 + thetaIncrease);
let y2 = this.y + this.r * sin(this.t2 + thetaIncrease);
//let x2 = x1 - 2 * this.r
//let y2 = y1 - 2 * this.r
line(x1, y1, x2, y2);
}
}
}