mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-27 14:01:12 +00:00
Added Code
This commit is contained in:
parent
ba2dde64e8
commit
55d965dc7c
52
scripts/Fidget spinner/fidgetspinner.py
Normal file
52
scripts/Fidget spinner/fidgetspinner.py
Normal 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()
|
||||
|
Loading…
Reference in New Issue
Block a user