diff --git a/scripts/Fidget spinner/fidgetspinner.py b/scripts/Fidget spinner/fidgetspinner.py new file mode 100644 index 0000000..f6851c6 --- /dev/null +++ b/scripts/Fidget spinner/fidgetspinner.py @@ -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() +