forked from tarunsinghofficial/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFidget - GAME
57 lines (46 loc) · 902 Bytes
/
Fidget - GAME
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
Fidget
Fidget, inspired by fidget spinners.
"""Fidget, inspired by fidget spinners.
Exercises
1. Change the spinner pattern.
2. Respond to mouse clicks.
3. Change its acceleration.
4. Make it go forwards and backwards.
"""
from turtle import *
state = {'turn': 0}
def spinner():
"Draw fidget spinner."
clear()
angle = state['turn'] / 10
right(angle)
forward(100)
dot(120, 'red')
back(100)
right(120)
forward(100)
dot(120, 'green')
back(100)
right(120)
forward(100)
dot(120, 'blue')
back(100)
right(120)
update()
def animate():
"Animate fidget spinner."
if state['turn'] > 0:
state['turn'] -= 1
spinner()
ontimer(animate, 20)
def flick():
"Flick fidget spinner."
state['turn'] += 10
setup(420, 420, 370, 0)
hideturtle()
tracer(False)
width(20)
onkey(flick, 'space')
listen()
animate()
done()