Code Toolkit: Python, Spring 2026

Week 4 — Wednesday, February 11 — Class notes

Table of contents for today

  1. Review of last week
    1. Homework review
  2. Conditionals and making things move (on their own)
    1. Background
  3. mousePressed and keyPressed
  4. Conditionals
  5. Keyboard interaction
  6. Events
  7. Making things move (on their own)

I. Review of last week

(jump back up to table of contents)

a. Homework review

Let's review some homework together ... In class together we reviewed JJ's homework. I made a copy of his homework folder (renamed by appending "_inclass") and made some slight changes in there. You can view that here.

We mainly practiced reading code by looking through what JJ put together and trying to determine what the composition would look like. We focused on lines 42-49 and realized that this would create three circles, with a smaller one to the upper-right, and a slightly smaller one to the bottom-left. We then talked about some of the other moving elements included here.

As a minor change, I moved his comment (the text inside triple quotes """ ) to the top of the file.

We also talked about a question Mara had asked about how to create trails, like we looked at last week, but instead of saving every single mark ever made by the sketch, to think about how to only save a smaller number of marks.

Coincidentally, JJ had already implemented exactly this. On lines 24 and 25 we see this:

    fill(skyR, skyG, skyB, trailAlpha)
    rect(0, 0, width, height)
This code is setting the fill color to something with some translucency, and then drawing a rectangle with that color. How big is the rectangle? It starts at 0,0 and it is as tall and wide as the entire winow (i.e. it uses the width and height keywords).

The full-window rectangle will have the same effect as background: it will, in effect, "wipe" the screen clean of past marks. However, since the color has some alpha (transparency) it won't fully wipe over past marks but instead will leave them partially visible. As more and more rectangles are layered on every frame, eventually the translucent layers get more and more opaque, creating a "fade out" effect.

Unfortunately using this technique it is not possible to have control over those trailed markingss in any way. You can't move them around or have them block things like in snake-style games. If you want to do that, you'll have to wait a couple weeks until we learn about lists.

[Thanks for sharing, JJ!]

II. Conditionals and making things move (on their own)

This week we will build on last week in two ways.

First, we will learn how to use conditionals so that instead of the continuous change of mouse movement, you can create movement that is discrete and discontinuous.

Second, we will build on our use of variables and Processing's interactive mode to create things that move on their own, not only as directly controlled by the mouse.

a. Background

Last week we saw how to make interactive compositions, but they were always moving in continuous, connected ways. Colors that changed as smooth gradients, and shapes that moved, resized, or left trails, but only ever directly correlated with mouse movement.

Today we will see how to work with one of the fundamental principles of digital media which is how to work with discontinuity, or on/off relationships — shapes that appear and disappear, or change their size and locations in discontinuous ways. This kind of behavior is often described as discrete. (Not to be confused with "discreet"!)

In 1997, the net artist John Simon created a project called Every Icon. This conceptul work enacts a play of combinatorics by starting with the first (top, left) pixel of a 32 by 32 grid, and advances in sequence, creating every possible combination of pixels, or in other works, every possible icon.

This work emphasizes the way that all digital images are created not as smooth strokes, continuous marks, or smooth lines, but rather always as grids of pixels, always turned either on or off.

To similar ends but in a more poetic and ironic way, the artist Hito Steyerl, in her documentary How Not to be Seen: A Fucking Didactic Educational .MOV File, explores (and blurs) the boundary between the analog and digital, between the physical world and the world of digital representations, or in other words, between the smooth and the discrete.

Let's keep all of this in the back of our minds as we explore the logic of discrete on/off structures today and dive in to binary logic.

(jump back up to table of contents)

III. mousePressed and keyPressed

(jump back up to table of contents)

IV. Conditionals

(jump back up to table of contents)

V. Keyboard interaction

(jump back up to table of contents)

VI. Events

Sidenote: There is a similar pattern here for the mouse. The mousePressed() block is also valid syntax and would be used in a similar way:
def setup():
    size(600,600)
    rectMode(CENTER)

def draw():
    background(255)

def mousePressed():
    ellipse( 300,300, 50,50 )
(jump back up to table of contents)

VII. Making things move (on their own)