Hexagonal Array, Dummy maths question.
in
Programming Questions
•
2 years ago
Hi there,
Im trying to make a simple honeycomb structure
I keep on going round in circles, I'm missing one simple computation somewhere.
Heres the code:
-
Hexagon[][] hexagon;int rad = 50;int hexcountx, hexcounty;
void setup(){size(300, 300);background(255);smooth();noFill();stroke(0);hexcountx = (height/(rad*2));hexcounty = (width/(rad*2));hexagon = new Hexagon [hexcountx][hexcounty];for (int i = 0; i < hexcountx; i++){for (int j = 0; j < hexcounty; j++){hexagon[i][j] = new Hexagon((2*rad*i), (rad*j), rad);}}}void draw(){for (int i = 0; i < hexcountx; i ++ ) {for (int j = 0; j < hexcounty; j ++ ) {// Oscillate and display each objecthexagon[i][j].display();}}}
class Hexagon{float x,y,radi;float angle = 360.0 / 6;Hexagon(float cx, float cy, float r){x=cx;y=cy;radi=r;}
void display(){beginShape();for (int i = 0; i < 6; i++){vertex(x + radi * cos(radians(angle * i)),y + radi * sin(radians(angle * i)));}endShape(CLOSE);}}
All the best
Miles
1