Exercise 1 · Chapter: Colour and TimeRequired+50 XP
A Ticking Clock
Before you can animate with time, you need time.
Write new_game so the state starts with "t" at 0, and update so it adds
1 every frame. draw doesn't have to do anything interesting yet — return a
blank grid.
That's it. The trace should read 1 2 3 4 5.
Small as this is, it's the foundation for the rest of the chapter: every colour you pick from here on is worked out from this one number.
Need a hint?
3 available · costs 5 XP each
python
def new_game():
# Start the clock at 0.
return {}
def update(state, keys):
# Add one to the clock each frame.
return state
def draw(state):
return blank_grid()