/* * Creates a hex grid of bricks, with visible border. * * Processing sketch by Michael Goldwasser */ int numRows = 21; int numCols = 10; // number in EVEN rows float r = 20; // radius of one hex float brickHeight = 2*r*sin(PI/3); void setup() { background(0); float w = 2.5*r*(numCols+2); float h = 0.5*(2+numRows) * brickHeight; size(int(w), int(h)); fill(178, 34, 34); // brick red stroke(205, 205, 193); // mortar color strokeWeight(3); for (int row=0; row < numRows; row++) { for (int col=row%2; col < numCols; col++) { float x = r*(3*col); if (row % 2 == 0) { x += 1.5*r; } float y = brickHeight * (0.75 + row / 2.0); drawBrick(x,y); } } } void draw() { } // draw a single brick of radius r, centered at (cx,cy) void drawBrick(float cx, float cy) { beginShape(); for (int j=0; j < 6; j++) { float x = r * cos(j*PI/3.0); float y = r * sin(j*PI/3.0); vertex(cx+x, cy+y); } endShape(CLOSE); }