void hexagon(float sideLength, float xPos, float yPos){ float c = sideLength; float a = cos(radians(30)) * c; float b = sin(radians(30)) * c; float[] A = { a+xPos, yPos }; float[] B = { 2 * a+xPos, b+yPos }; float[] C = { 2 * a+xPos, b + c +yPos }; float[] D = { a+xPos, 2 * c +yPos }; float[] E = { a / c+xPos, b + c +yPos }; float[] F = { a / c +xPos, b + yPos }; beginShape(); vertex(A[0], A[1]); vertex(B[0], B[1]); vertex(C[0], C[1]); vertex(D[0], D[1]); vertex(E[0], E[1]); vertex(F[0], F[1]); vertex(A[0], A[1]); endShape(); } void drawHexagon(float sideLength, int hNum, int vNum, int Color, int[][] Category){ for(int i = 0; i < hNum; i++){ for (int j = 0; j< vNum; j++){ float alphaCate = map(Category[i][j],0,MaxTrans(Category),40,255); fill(colorIdx[Color][0],colorIdx[Color][1],colorIdx[Color][2],alphaCate); if(j%2==0){ noStroke(); hexagon(sideLength, i*sideLength*sqrt(3), int(j)/2*3*sideLength); }else{ pushMatrix(); translate(sideLength*sqrt(3)/2, 3*sideLength/2); hexagon(sideLength, i*sideLength*sqrt(3), int(j/2)*3*sideLength); popMatrix(); } } } } void drawGrid(float sideLength, int hNum, int vNum){ for(int i = 0; i < hNum; i++){ for (int j = 0; j< vNum; j++){ stroke(100); noFill(); hexagon(sideLength, i*sideLength*sqrt(3), j*3*sideLength); pushMatrix(); translate(sideLength*sqrt(3)/2, 3*sideLength/2); stroke(100); noFill(); hexagon(sideLength, i*sideLength*sqrt(3), j*3*sideLength); popMatrix(); } } } void drawGridSingle(float sideLength, int hNum, int vNum){ for(int i = 0; i < hNum; i++){ for (int j = 0; j< vNum; j++){ //stroke(100); noFill(); hexagon(sideLength, i*sideLength*sqrt(3), j*3*sideLength); pushMatrix(); translate(sideLength*sqrt(3)/2, 3*sideLength/2); //stroke(100); noFill(); hexagon(sideLength, i*sideLength*sqrt(3), j*3*sideLength); popMatrix(); } } } int MaxTrans(int[][] Category){ int MaxTrans=0; for(int i = 0; i < 10; i++){ for(int j = 0; j < 30; j++){ if(Category[i][j]>MaxTrans){ MaxTrans = Category[i][j]; } } } return(MaxTrans); }