// var points = [];
int numsquares = 64;
float[] points = new float[numsquares];
ArrayList<Hexagon> hexagons = new ArrayList<Hexagon>();
void setup() {
size(1000, 800);
for (int i = 0; i < numsquares; i++) {
points[i] = (map(i, 0, numsquares, 0, PI / 2));
hexagons.add(new Hexagon(map(i, 0, i + 1, height * 2, 0)));
}
}
void draw() {
background(255);
noStroke();
for (int i = 0; i < points.length; i++) {
if (i % 2 == 1) fill(0);
else fill(255);
pushMatrix();
translate(width / 2, height / 2);
rotate(sin(points[i]) * TWO_PI);
hexagons.get(i).display();
popMatrix();
points[i] += 0.02;
}
}
class Hexagon {
PVector[] points = new PVector[6];
float a;
public Hexagon(float d) {
for (int i = 0; i < 6; i++) {
this.a = map(i, 0, 6, 0, TWO_PI);
this.points[i] = new PVector(cos(this.a) * d, sin(this.a) * d, this.a);
}
}
void display() {
beginShape();
for (int i = 0; i < this.points.length; i++) {
vertex(this.points[i].x, this.points[i].y);
}
endShape(CLOSE);
}
}