-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
30 lines (21 loc) · 819 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pygame
import math
FIELD_WIDTH = 800
FIELD_HEIGHT = 500
DELAY = 50
def x_comp(vector_len, angle):
"""returns the x component of a vector given its magnitude and direction"""
return math.cos(angle) * vector_len
def y_comp(vector_len, angle):
"""returns the y component of a vector given its magnitude and direction"""
return math.sin(angle) * vector_len
def rotate_point(center, point, angle):
"""rotates a point around a center by a certain angle"""
diff_x = point[0] - center[0]
diff_y = point[1] - center[1]
point[0] = center[0] + diff_x * math.cos(angle) - diff_y * math.sin(angle)
point[1] = center[1] + diff_x * math.sin(angle) + diff_y * math.cos(angle)
def rotate_vertices(vertices, center, angle):
"""rotates all vertices"""
for point in vertices:
rotate_point(center, point, angle)