Added Code

This commit is contained in:
Harshavardhan Bajoria 2022-10-03 19:52:59 +05:30 committed by GitHub
parent ba2dde64e8
commit 55d965dc7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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()