Skip to content

Instantly share code, notes, and snippets.

@rnistuk
Created May 14, 2020 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnistuk/044960ec046ee7c2f92196d77e5ae2db to your computer and use it in GitHub Desktop.
Save rnistuk/044960ec046ee7c2f92196d77e5ae2db to your computer and use it in GitHub Desktop.
point pointy_hex_corner(point center, float size, int i) {
float angle_deg = 60 * i - 30;
float angle_rad = (M_PI / 180.0) * angle_deg;
return point{center.x + size * cos(angle_rad),
center.y + size * sin(angle_rad)};
}
void drawPointyHex(point center, float hex_size) {
point p0 = pointy_hex_corner(center, hex_size, 0);
point p=p0;
for (int i=1; i<6; ++i) {
point np = pointy_hex_corner(center, hex_size, i);
drawLine(p.x,p.y,np.x,np.y);
p = np;
}
drawLine(p.x,p.y,p0.x,p0.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment