Skip to content

Instantly share code, notes, and snippets.

@cocuh
Created July 11, 2013 02:26
Show Gist options
  • Save cocuh/5972023 to your computer and use it in GitHub Desktop.
Save cocuh/5972023 to your computer and use it in GitHub Desktop.
int HEXNUM = 32;
int HEXC = 5;
int r=576/12;
Hex[] hexarr = new Hex[HEXNUM];
void setup(){
size(1024, 576);
frameRate(50);
int i, j, k, l;
i = 0;
for (j = 0; j < 5; j++) {
//j=x axis
for (k = 0; k < 7 - (j % 2); k++) {
if (j % 2) {
l = floor(abs(k - 2.5) - j / 2);
} else {
l = floor(abs(k - 3) - j / 2);
}
if (l < 0) {
l = 0
}
hexarr[i] = hex(-2 * (l + j) - 1, 5 * r * (j + 1), 2 * k * r + r * (j % 2));
i++;
}
}
}
void draw(){
background(0);
int i;
for(i=0;i<hexarr.length;i++){
hexarr[i].draw()
}
}
class Hex
{
float x,y,c,a;
int ratio=1;
float cdicx[5] = [-5*r,-2*r,-0.8*r,-0.12*r,-0.04*r];
float cdica[5] = [0.1, 0.2,0.4,0.5,0.5];
Hex(int _c;float _x, float _y){
this.c = _c;
this.x = _x;
this.y = _y;
}
void move(){
if(c<dicx.length){
this.x += cdicx[this.c]/this.ratio;
}
if(c<dicx.length){
this.a = cdica[this.c]/this.ratio;
}
this.c++;
}
void draw(){
float posx = this.x;
float posy = this.y;
noStroke();
fill(1,1,1,this.a)
beginShape(POLYGON);
vertex(posx, posy);
vertex(posx + r, posy + r);
vertex(posx + 5 * r, posy + r);
vertex(posx + 6 * r, posy);
vertex(posx + 5 * r, posy - r);
vertex(posx + r, posy - r);
vertex(posx, posy);
endShape();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment