Merge pull request #94 from HVbajoria/master

Fidget Spinner
This commit is contained in:
Bartick Maiti 2022-10-03 22:14:08 +05:30 committed by GitHub
commit b54fab6098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# Fidget Spinner With Python
This is a fidget spinner simulator made using Python which can help you release nervous energy, and anxiety and stay calm.
## How to install?
1) Download the file fidgetspinner.py
2) Open CMD (Command Prompt)
3) Run python fidgetspinner.py
4) Press the spacebar 5-6 times and see it accelerating with the press.
## Requirements?
None!
Hope you enjoy it! ❤️

View File

@ -0,0 +1,52 @@
#Import libraries and modules
from turtle import *
state = {'turn': 0}
# Function to spin the fidget
def spinner():
clear()
angle = state['turn']/8
right(angle)
forward(100)
# Declare first dot
dot(200, 'teal')
back(100)
right(120)
forward(100)
# Declare second dot
dot(200, 'peach puff')
back(100)
right(120)
forward(100)
# Declare third dot
dot(200, 'navy')
back(100)
right(120)
update()
# Function that slows down the widget with time and spins it
def animate():
if state['turn']>0:
state['turn']-=1
spinner()
ontimer(animate, 20)
# Flick the fidget based on number of clicks
def flick():
state['turn']+=12
# Define window size
setup(520, 520, 370, 0)
hideturtle()
tracer(False)
width(20)
# Call the function with clicks on spacebar
onkey(flick, 'space')
listen()
animate()
done()