+ 2

# Rotate polygon on pygame

How to rotate a polygon on pygame

1 Réponse

0

It looks like you have a couple options.
Option 1:
pygame.transform.rotate() might do what you're looking for. There is a video of an instructor explaining how to use transform.rotate to rotate an image at:
https://www.youtube.com/watch?v=OcfeqRkOkug
You should be able to draw your polygon or triangle on a new surface and treat the surface like he treats the image he loaded from a file.
More details can be found at: http://blog.tankorsmash.com/?p=128
Option 2:
If you like math, you could use Python's math package to rotate your polygon's points. You could convert your points to a polar coordinate format which includes radius and angle. This means you just add a rotation angle to each vertex and you'd represent the new rotation angle for your polygon. Rotation in the polar coordinate system is as simple as moving your shape up/down, left/right in x-y coordinates. When you want to draw, you can then follow formals such as:
x = cx + r * math.cos(a + rotation_angle),
y = cy + r * math.sin(a + rotation_angle).
Note that Python's math sin and cos functions interpret the parameter as being in radians instead of degrees. 180 degrees == math.pi radians.