Skip to content

Commit 20801b5

Browse files
Merge pull request prathimacode-hub#496 from neelshah2409/main
Fidget Spinner
2 parents f6c11bc + 189a858 commit 20801b5

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Fidget Spinner(Game)
2+
3+
## Short description of package/script
4+
### Logic:
5+
The logic of the game is that the turns will keep increasing as you press the space bar, and it will reduce its speed and stop at a point where you stop pressing the space bar.
6+
Here we will use distutils for functioning and turtle for the animation.
7+
## List out the libraries imported:
8+
distuntils, turtle
9+
10+
## Setup instructions
11+
12+
Here for setup we not need to do anything just running the script and then we need to press space button to spin the fidget as fast we press the speed increases.
13+
14+
## Output
15+
16+
![image](Images/output(fidget).png)
17+
18+
## Author(s)
19+
20+
Neel Shah
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#The logic of the game is that the turns will keep increasing as
2+
#you press the space bar, and it will reduce its speed and
3+
#stop at a point where you stop pressing the space bar.
4+
5+
from distutils.core import setup
6+
from turtle import *
7+
state = {'turn': 0}
8+
#definning the spinner
9+
def spinner():
10+
clear()
11+
angle = state['turn']/10
12+
right(angle)
13+
forward(100)
14+
dot(120, 'red')
15+
back(100)
16+
right(120)
17+
forward(100)
18+
dot(120, 'brown')
19+
back(100)
20+
right(120)
21+
forward(100)
22+
dot(120, 'orange')
23+
back(100)
24+
right(120)
25+
update()
26+
#creating the animation
27+
def animate():
28+
if state['turn']>0:
29+
state['turn']-=1
30+
31+
spinner()
32+
ontimer(animate, 20)
33+
def flick():
34+
state['turn']+=10
35+
36+
setup(420, 420, 370, 0)
37+
hideturtle()
38+
tracer(False)
39+
width(20)
40+
onkey(flick, 'space')
41+
listen()
42+
animate()
43+
done()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Libraries used:turtle, distutils

0 commit comments

Comments
 (0)