I'm creating an image filter that will create a honeycomb effect by finding the averages of groups of hexagons. This code will generate a grid of hexagons for any given size, and will eventually be limited to the size of the canvas:
float unitSize = 20;
float eqTriH = 0.8660254;
int cellsX;
int cellsY;
void setup() {
size(700, 700);
cellsX = int(width/(unitSize*3));
cellsY = int(height/(unitSize*eqTriH*2+eqTriH));
smooth();
}
void draw() {
for (int i = 0; i < cellsX; i++) {
for (int j = 0; j < cellsY; j++) {
beginShape();
for (int k = 0; k < 6; k++) vertex(unitSize+i*unitSize*3+cos(TWO_PI/6*k)*unitSize, unitSize*eqTriH+j*unitSize*2*eqTriH+sin(TWO_PI/6*k)*unitSize);
endShape(CLOSE);
beginShape();
for (int k = 0; k < 6; k++) vertex(unitSize*2.5+i*unitSize*3+cos(TWO_PI/6*k)*unitSize, unitSize*eqTriH*2+j*unitSize*2*eqTriH+sin(TWO_PI/6*k)*unitSize);
endShape(CLOSE);
}
}
}
This works fine, however, I can't figure out how to, for every hexagon that is drawn, get an array of pixel locations inside each hexagon.
If this question is too vague, please let me know so I can get more specific.
EDIT: when I say I want to determine if a pixel is in the shape, I mean, once I can do this, I'm going to loop through, THEN create an array.