Nifty Assignment: Optical Illusions using loops and nested loops

Faan Tone Liu

The assignment is to reproduce one of several choices of optical illusions. Part 1 of the assignment requires only loops, while part 2 requires nested loops. Students are asked to modify the image in some (possibly small) way.

Students and instructors find the images themselves interesting and surprising. So the assignment is fun for the students to do.

We don't give starter code or instructions on how to draw the images, as the visual problem solving is part of the fun of the assignment. However, the task is scaffolded by previous assignments in which they have drawn images and animations using loops.

What is unusual about the assignment is that it can be given very early in CS1 (after 2-3 weeks for part 1, after 3-4 weeks for part 2). Students must already be familiar with a basic graphics package, variables, and loops. Two of the options require them to be familiar with animation.

We give multiple options of images for the students to reproduce. The students choose their own level of challenge. We see the more advanced students choosing a more difficult option and taking the assignment to a higher level (especially if offered even a nominal point bonus). The easiest choice is accessible to essentially all of the students.

Summary Create an optical illusion using a graphics primitive package, choosing from several options of increasing difficulty
Topics
A visually exciting application of for-loops and nested for loops, variables, and using graphics primitives
Audience
Appropriate at end of first 3 or 4 weeks of CS1 course.
Difficulty and length
Since students may self-select which image to recreate, the assignment provides a high degree of differentiation of difficulty. The first image is easy to create, some of the later ones are difficult. We assign this as one of our weekly projects, with concurrent additional homework. The easiest choice of images can be done by most students in an hour, but students that get involved in and excited by the project can elect to spend many hours reproducing several of the images or animations.
Strengths
One strength of this assignment is that students find the images exciting and interesting. Another strength is that this cool assignment can be successfully completed very early in a CS1 course. A third strength is that there is a wide variety of difficulty to appeal to and challenge the broad range of abilities we see in a first programming course.
Weaknesses
The students must have some experience with a drawing package that includes simple graphics primitives, possibly including animation.
Dependencies
Students must have competence with variables, assignment, loops and nested loops.
Variants
The instructor can include or omit images based on capabilities of their graphics packages, and based on the difficulty they want to present to their students. The assignment applies to any programming language used, provided the students are familiar with a basic graphics package. Students could create illusions of their own. I'd love to see instructors or students share their own creations to add to the assignment options.

Links to student-facing assignment, parts 1 and 2:

Part 1 of nifty optical illusions assignment (loops)
Part 2 of nifty optical illusions assignment (nested loops)

Summary reference tables (for instructor use) showing which graphics primitives are necessary for each illusion

Part 1: loops

Gradient Illusion Change drawing color
Draw narrow line segment (or narrow filled rectangle)
Draw filled rectangle
Curving squares Change drawing color
Change line width
Draw circle outline
Draw square outline
Hering Illusion Change drawing color
Draw line segment
Students know enough trigonometry to draw a ray
(or your graphics package has a ray function)
Eisenstein Illusion Change drawing color
Draw line segment
Students know enough trigonometry to draw a polar ray
(or your graphics package has a ray function
Draw circle outline
Draw square outline
Leviant Enigma Change drawing color
Draw sector
Change line width
Draw sector of circle

Part 1: (nested loops)

Hermann Scintillating Grid Change drawing color
Change background color (or draw filled rectangle to cover background)
Change line width
Draw line segments (or narrow filled rectangle)
Draw filled circle
Hermann Scintillating Grid, Polar Form Change drawing color
Change background color (or draw filled rectangle to cover background)
Change line width
Draw line segment
Students know enough trigonometry to draw a part of a polar ray
Change line width
Draw circle outline
Cafe Wall Illusion Change drawing color
Change line width
Draw line segment
Draw filled rectangle
Victoria Skye's Cafe Wall Illusion Change drawing color
Change line width
Draw line segment
Draw filled rectangle
Image of a cat's face, masked with a checkboard of black squares Change drawing color
Use image as a background
Either edit your image in a photo editor to brighten it
Or if your graphics package allows you to get and modify colors of pixels, then modify the background in the program
Draw filled rectangle



Change drawing color
Draw narrow line segment (or narrow filled rectangle)
Draw filled rectangle
Animation
Change drawing color
Draw filled rectangle
Animation