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
defsetup():
size(256, 256)
frameRate(1)
defdraw():
global y
if y < height:
text(y, 230, y/2)
line (0, y, width-y, 0)
y = y + 40
RECURSION
defsetup():
size(256, 256)
stringart(0)
defstringart(y):
if y < height:
text(y, 230, y/2)
line (0, y, width-y, 0)
stringart(y + 40)
Warm Up: String Art
Compare your traces with your partner;
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.
Part 0: String Art (before lab)
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
Vinyl
def setup():
size(256, 256)
def draw():
background(24)
vinyl(width/2, height/2, 150)
vinyl(mouseX, mouseY, 150)
Line Moire