Transformation[] trans;
int amount = 10;
void setup() {
size(640, 640);
strokeJoin(ROUND);
trans = new Transformation[amount];
float diff = 90/amount;
for (int i = 0; i < amount; i++) {
float s = (i+1)*diff*2;
trans[i] = new Transformation(new PVector(width/2, height/2), s, (amount-i)*diff);
}
}
void draw() {
background(30);
for (int i = 0; i < trans.length; i++) {
trans[i].draw();
trans[i].move();
}
}
class Transformation {
PVector loc;
boolean timer = false, turn = false;
float num = 90, offset, s, weight = random(1, 6);
color c;
Transformation(PVector loc, float s, float offset) {
this.loc = loc.get();
this.s = s;
this.offset = offset;
if ((s%4)==0) {
c = color(220, 53, 34);
} else {
c = color(217, 203, 158);
}
}
void draw() {
noFill();
pushMatrix();
translate(loc.x, loc.y);
rotate(radians(num-2)+QUARTER_PI);
stroke(0);
strokeWeight(weight+2);
beginShape();
for (float i = 0; i <= 360; i+=9) {
float angle = sin(radians(num));
float x = cos(radians(i));
float y = sin(radians(i));
float x2 = x * sqrt(1 - angle*pow(y, 2))*s;
float y2 = y * sqrt(1 - angle*pow(x, 2))*s;
vertex(x2, y2);
}
endShape();
stroke(c);
strokeWeight(weight);
beginShape();
for (float i = 0; i <= 360; i+=9) {
float angle = sin(radians(num));
float x = cos(radians(i));
float y = sin(radians(i));
float x2 = x * sqrt(1 - angle*pow(y, 2))*s;
float y2 = y * sqrt(1 - angle*pow(x, 2))*s;
vertex(2+x2, 2+y2);
}
endShape();
popMatrix();
}
void move() {
if ((offset%(90))==0) {
timer = !timer;
}
if ((offset%(180))==0) {
turn = !turn;
}
if (timer) {
if (turn) {
if (num >= -2 && num < 92) {
num+=2;
}
} else {
if (num <= 92 && num >= 0) {
num-=2;
}
}
}
offset++;
}
}