← All scenes

Moving

A circle crossing the picture: update(dt) and one number. Change the 200 in the code to change its speed.

# Moving: a circle that crosses the picture, again and again.
# Try changing: 200, its speed; 40, its size.
#
# Run it:   pyctures run moving.py

x = 0

def update(dt):
    global x
    x += 200 * dt            # 200 points every second
    if x > width:            # off the right edge: start again on the left
        x = 0

def draw():
    background("midnightblue")
    circle(x, height / 2, 40, "gold")

Run it yourself

pip install pyctures
pyctures run moving.py

Put it on your website

pyctures build moving.py -o site/

Python runs in the visitor's browser, so any static host works. How · This file on GitHub