-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintermediate.py
71 lines (50 loc) · 1.74 KB
/
intermediate.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
# V2 - INTERMEDIATE
# import statements
import simplegui
import time
import math
# set width and height of frame
frame_width = 600
frame_height = 600
# fields for the dots
dot_radius = 5
dot_width = 1
dot_colours = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Purple']
dots = []
# returns [x, y] of parametric equation points
def get_dot_coords(t):
# circle
#return [(math.cos(t) * 100 + (0.5 * frame_width)), (math.sin(t) * 100 + (0.5 * frame_height))]
# star
#return [((2 * math.cos(t) + 5 * math.cos(2*t/3)) * 10 + (0.5 * frame_width)),
# ((2 * math.sin(t) - 5 * math.sin(2*t/3)) * 10 + (0.5 * frame_height))]
# flower
return [((math.cos(t) * math.sin(4*t)) * 100 + (0.5 * frame_width)),
((math.sin(t)*math.sin(4*t))*100 + (0.5 * frame_height))]
# creates the next dot: (x, y)
def new_dots(t):
coords = get_dot_coords(t)
#colour = get_dot_colour()
dots.append(coords)
def draw(canvas):
t = time.time() # get current time
new_dots(t)
# draw each dot in 'dots' list onto canvas
for i in range(len(dots)):
canvas.draw_circle(dots[i],
dot_radius,
dot_width,
dot_colours[i % len(dot_colours)], # cycle through dot colours in order
dot_colours[i % len(dot_colours)])
# create a frame
frame = simplegui.create_frame("Parametric Equations", frame_width, frame_height)
# assign draw handler to frame
frame.set_draw_handler(draw)
# create time Handler
def timer_handler():
draw
# set and start the timer
timer = simplegui.create_timer(500, timer_handler)
timer.start()
# start the frame animation
frame.start()