Created
May 14, 2020 15:50
-
-
Save rnistuk/044960ec046ee7c2f92196d77e5ae2db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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