Python exercises for ages 10+

Create an old-school DVD screensaver

Part 1

Run the below code. Given that the render function is called every 10 milliseconds, how many frames per second are rendered? There are 1000 milliseconds in a second. What is the square’s speed in pixels per second?

from tkinter import *

c = Canvas(Tk(), width = 500, height = 500)

x = 0
y = 0
size = 50

def render():
    global x
    global y

    c.create_rectangle(x, y, x + size, y + size, fill="black")
    x = x + 1
    y = y + 1

    c.after(10, render)


Part 2

Detect when the square reaches the bottom right corner. When it does, have it change direction such that it moves by (-1, -1) per frame, and also have it change colour to a colour of your choice. Refer to documentation for a list of valid colours.