Lab 2: Multiples/Illusions
Bard College – Computer Science – Object-Oriented Programming

Explore some visual illusions like Moiré patterrns and the Hermann’s grid illusion, and practice using loops and recursion. Use for loops or recursion (try and use each at least once).

BONUS: Try and write each example using for, while, as well as recursion. 
Try using for along with range and without; forward & backward, same with while.

Part 0: String Art (before lab)

Trace the following two programs by hand using graph paper:

DRAW LOOP

y = 0

def setup():
    size(256, 256)
    frameRate(1)
        
def draw():
    global y
    if y < height:
        text(y, 230, y/2)
        line (0, y, width-y, 0)
        y = y + 40

RECURSION

def setup():
    size(256, 256)
    stringart(0)
        
def stringart(y):
    if y < height:
        text(y, 230, y/2)
        line (0, y, width-y, 0)
        stringart(y + 40)

Warm Up: String Art

  1. Compare your traces with your partner;
  1. Together, modify stringart() to use a for loop instead of recursion.

Vinyl

Create a function called vinyl(midx, midy, diameter) that draws a series of circles; if you drag the circle around you can start to see a Moiré pattern.

def setup():
    size(256, 256)

def draw():
    background(24)
    vinyl(width/2, height/2, 150)
    vinyl(mouseX, mouseY, 150)

Line Moire