forked from VideojogosLusofona/imfj1_2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trig_circle1.py
74 lines (57 loc) · 2.1 KB
/
trig_circle1.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Import pygame into our program
import pygame
import pygame.freetype
import math
import time
from helpers import *
# Define a main function, just to keep things nice and tidy
def main():
# Initialize pygame, with the default parameters
pygame.init()
# Define the size/resolution of our window
res = (640, 360)
# Create a window and a display surface
screen = pygame.display.set_mode(res)
# Load a font
axis_labels_font = pygame.freetype.Font("NotoSans-Regular.ttf", 12)
angle = 45
# Game loop, runs forever
while (True):
# Process OS events
for event in pygame.event.get():
# Checks if the user closed the window
if (event.type == pygame.QUIT):
# Exits the application immediately
exit()
# Clears the screen with a very dark blue (0, 0, 20)
screen.fill((0,0,20))
# Draw grid
draw_grid(screen, 240, 260, 100, 2, 2, 5, (255, 255, 0, 255), axis_labels_font, [str(i) for i in range(-1, 2)], [str(i) for i in range(-1, 2)])
# Draw circle
pygame.draw.circle(screen, (255,128, 0, 255), (340, 160), 100, 2)
c = math.cos(math.radians(angle))
s = math.sin(math.radians(angle))
draw_triangle(screen, (340, 160), (340 + c * 100, 160), (340 + c * 100, 160 - s * 100), (0, 255, 0,255), 2)
angle_start = 0
angle_end = 0
if (angle > 270):
angle_start = angle
angle_end = 360
elif (angle > 180):
angle_start = 180
angle_end = angle
elif (angle > 90):
angle_start = angle
angle_end = 180
else:
angle_start = 0
angle_end = angle
pygame.draw.arc(screen, (0, 255, 255, 255), [315, 135, 50, 50], math.radians(angle_start), math.radians(angle_end), 2)
# Swaps the back and front buffer, effectively displaying what we rendered
pygame.display.flip()
angle = angle + 5
if (angle > 360):
angle = angle - 360
time.sleep(0.1)
# Run the main function
main()