-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (55 loc) · 2.31 KB
/
main.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
75
76
77
import pygame
from radioButton import RadioButton
from slider import Slider
from bezier_path import BezierPath
pygame.init()
pygame.font.init()
WIDTH, HEIGHT = 1080,720
BG_COLOR = (128, 128, 128)
DOT_COLOR = (230,230,230)
LINE_COLOR = (230,230,230)
FPS = 60
CLOCK = pygame.time.Clock()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Bezier Curves')
def main():
radio_button = RadioButton((30, 30), (255, 255, 255), 12, "Guidelines")
radio_button2 = RadioButton((30, 70), (255, 255, 255), 12, "Dots")
slider_t = Slider((18, 100), (200, 10), (255, 255, 255) , 1, "t =")
slider_q = Slider((18, 130), (200, 10), (255, 255, 255), 0.05, "Q =")
bezier_path = BezierPath((150,300), DOT_COLOR, LINE_COLOR, WIDTH, HEIGHT)
Ctrl_key_state = False
show_guidelines = False
while True:
CLOCK.tick(FPS)
for event in pygame.event.get():
if event.type==pygame.QUIT:
exit()
if event.type == pygame.KEYDOWN and pygame.K_LCTRL:
Ctrl_key_state = True
if event.type == pygame.KEYUP and event.key == pygame.K_LCTRL:
Ctrl_key_state = False
if event.type == pygame.MOUSEBUTTONUP and event.button == 1:
if Ctrl_key_state:
mouse_position = pygame.mouse.get_pos()
bezier_path.generate_new_dot(mouse_position)
radio_button.mouse_trigger(event)
radio_button2.mouse_trigger(event)
slider_t.mouse_trigger(event)
slider_q.mouse_trigger(event)
bezier_path.mouse_trigger(event)
mouse_position = pygame.mouse.get_pos()
screen.fill(BG_COLOR)
radio_button.update(screen, mouse_position)
show_guidelines = radio_button.get_state()
radio_button2.update(screen, mouse_position)
show_dots = radio_button2.get_state()
slider_t.update(screen, mouse_position)
t_max = slider_t.get_swiper_percentage()
slider_q.update(screen, mouse_position)
Q = slider_q.get_swiper_percentage()
Q = 0.01 if Q <=0 else Q
bezier_path.update(screen, mouse_position, t_max, Q, show_guidelines,show_dots)
pygame.display.update()
if __name__ == "__main__":
main()