← All scenes

Follow

A circle you move. Arrow keys, or hold the mouse or a finger on it.

# Follow: a circle you move.
# Use: the left and right arrow keys, or hold the mouse button or a finger on the picture. Click it first, so it has the keyboard.
# Try changing: 300, its speed; 40, its size.
#
# Run it:   pyctures run follow.py

x, y = 200, 150

def update(dt):
    global x, y
    if "ArrowLeft" in keys: x -= 300 * dt
    if "ArrowRight" in keys: x += 300 * dt
    if mouse.down:           # a mouse button, or a finger
        x, y = mouse.x, mouse.y

def draw():
    background("midnightblue")
    circle(x, y, 40, "gold")

Run it yourself

pip install pyctures
pyctures run follow.py

Put it on your website

pyctures build follow.py -o site/

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