The angle of your pencil with respect to where you started is measured in radians.
Now trace along the outer edge of the circle counterclockwise, starting from the 3 o'clock position. This circle is centered at the origin (0, 0). Imagine a circle whose radius is exactly length 1. The key here is the sine and cosine trigonometric functions, which, if you remember back to high school trigonometry, give the ratio of lol don't panic, no one remembers.īut here's a quick picture of everything you need to know, in terms of using them in graphics: X = x + radius * s(tiltAngle + math.pi * 2 * i / numSides)
But first I'll give the code to do this and then pick it apart with the explanation afterwards: def drawRegularPolygon(surface, color, numSides, tiltAngle, x, y, radius): In order to do this generically for all polygons, you'll have to think back to your trigonometry. But this isn't very convenient for drawing a simple regular polygon like a simple honeycomb hexagon, or even a 4-sided diamond. It takes in a list of points and a color and creates a filled-in polygon with corners at those locations. There's a method in pygame to draw an arbitrary polygon.