Skip to content

Instantly share code, notes, and snippets.

@seabre
Created October 14, 2011 15:24
Show Gist options
  • Save seabre/1287416 to your computer and use it in GitHub Desktop.
Save seabre/1287416 to your computer and use it in GitHub Desktop.
Drawing a Hexagon in Processing
void hexagon(int x, int y, int edge_length) {
float c = (float) edge_length;
float a = .5 * c;
float b = sin(radians(60)) * c;
float xf = (float) x;
float yf = (float) y;
/* Fill with a color of your choice. */
fill(0,174,239);
beginShape();
vertex(0 + xf,b + yf);
vertex(a + xf,2 * b + yf);
vertex(a + c + xf,2 * b + yf);
vertex( 2 * c + xf,b + yf);
vertex(a + c + xf,0 + yf);
vertex(a + xf,0 + yf);
endShape(CLOSE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment