DEV Community

Michael Oden
Michael Oden

Posted on

How to create a fidget spinner using python.

Hello, I got an idea for a practical example on how to create animations using python and I thought a fidget spinner showing three different colours will be brilliant.

Here is a step by step breakdown of the code to help you create the same thing or something similar.

#How to create a Fidget Spinner game using python.

from turtle import *
state ={'turn': 0}
def spinner ():
    clear()
    angle = state['turn']/10
    right(angle)
    forward(100)
    dot(120, 'red')
    back(100)
    right(100)
    forward(100)
    dot(120, 'green')
    back(100)
    right(120)
    forward(100)
    dot(120, 'blue')
    back(100)
    right(120)
    update()
def animate():
    if state['turn']>0:
        state['turn']-=1
    spinner() 
    ontimer(animate, 20)
def flick():
    state['turn']+=10
setup(420, 420, 360, 0)
hideturtle()
tracer(False)
width(20)
onkey(flick, 'space')
listen()
animate()
done()
Enter fullscreen mode Exit fullscreen mode

Oldest comments (0)