Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified example5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame26.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame27.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame28.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frame30.png
Binary file added frame31.png
Binary file added frame32.png
Binary file added frame33.png
Binary file added frame34.png
Binary file added frame35.png
Binary file added frame36.png
Binary file added frame37.png
Binary file added frame38.png
Binary file added frame39.png
Binary file added frame4.png
Binary file added frame40.png
Binary file added frame41.png
Binary file added frame42.png
Binary file added frame43.png
Binary file added frame44.png
Binary file added frame45.png
Binary file added frame46.png
Binary file added frame47.png
Binary file added frame48.png
Binary file added frame49.png
Binary file added frame5.png
Binary file added frame50.png
Binary file added frame51.png
Binary file added frame52.png
Binary file added frame53.png
Binary file added frame54.png
Binary file added frame55.png
Binary file added frame56.png
Binary file added frame57.png
Binary file added frame58.png
Binary file added frame59.png
Binary file added frame6.png
Binary file added frame7.png
Binary file added frame8.png
Binary file added frame9.png
Binary file added mymovie.avi
Binary file not shown.
72 changes: 36 additions & 36 deletions recursive_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def build_random_function(min_depth, max_depth):
return functions[random.randint(7, 8)]


def evaluate_random_function(f, x, y):
def evaluate_random_function(f, x, y, t):

""" Evaluate the random function f with input x
Representation of the function f is defined in the assignment writeup
Expand All @@ -55,28 +55,28 @@ def evaluate_random_function(f, x, y):
functions = {1: "prod", 2: "avg", 3: "cos_pi", 4: "sin_pi",
5: "arctan", 6: "step", 7: "x", 8: "y"}
if len(f) == 3:
eval1 = evaluate_random_function(f[1], x, y)
eval2 = evaluate_random_function(f[2], x, y)
eval1 = evaluate_random_function(f[1], x, y,t)
eval2 = evaluate_random_function(f[2], x, y,t)
elif len(f) == 2:
eval1 = evaluate_random_function(f[1], x, y)
eval1 = evaluate_random_function(f[1], x, y,t)

if f[0] == functions[1]:
return eval1 * eval2
elif f[0] == functions[2]:
return 0.5 * (eval1 + eval2)
return 0.5 * (eval1 + eval2)
elif f[0] == functions[3]:
return math.cos(math.pi * eval1)
return math.cos(math.pi * eval1 + t)
elif f[0] == functions[4]:
return math.sin(math.pi * eval1)
return math.sin(math.pi * eval1 + t)
elif f[0] == functions[5]:
return math.atan(eval1)/(math.pi)/2
elif f[0] == functions[6]:
if eval1 > 0:
return 1
elif eval1 == 0:
return 0
elif eval1 < 0:
return -1
#if eval1 > 0:
return 1
# elif eval1 == 0:
# return 0
# elif eval1 < 0:
# return -1
elif f[0] == functions[7]:
return x
elif f[0] == functions[8]:
Expand Down Expand Up @@ -158,33 +158,33 @@ def test_image(filename, x_size=350, y_size=350):
im.save(filename)


def generate_art(filename, x_size=350, y_size=350):
def generate_art(filename, x_size=350, y_size=350, frames = 5):
""" Generate computational art and save as an image file.

filename: string filename for image (should be .png)
x_size, y_size: optional args to set image dimensions (default: 350)
"""
# Functions for red, green, and blue channels - where the magic happens!
red_function = build_random_function(8, 8)
green_function = build_random_function(8, 8)
blue_function = build_random_function(8, 8)

# Create image and loop over all pixels
im = Image.new("RGB", (x_size, y_size))
pixels = im.load()
for i in range(x_size):
for j in range(y_size):
print "i: " + str(i)
print "j: " + str(j)
x = remap_interval(i, 0, x_size, -1, 1)
y = remap_interval(j, 0, y_size, -1, 1)
pixels[i, j] = (
color_map(evaluate_random_function(red_function, x, y)),
color_map(evaluate_random_function(green_function, x, y)),
color_map(evaluate_random_function(blue_function, x, y))
)

im.save(filename)

# Functions for red, green, and blue channels - where the magic happens!
red_function = build_random_function(5, 8)
green_function = build_random_function(3, 8)
blue_function = build_random_function(2, 8)
for t in xrange(frames):
# Create image and loop over all pixels
im = Image.new("RGB", (x_size, y_size))
pixels = im.load()
for i in range(x_size):
for j in range(y_size):
x = remap_interval(i, 0, x_size, -1, 1)
y = remap_interval(j, 0, y_size, -1, 1)
pixels[i, j] = (
color_map(evaluate_random_function(red_function, x, y,t)),
color_map(evaluate_random_function(green_function, x, y,t)),
color_map(evaluate_random_function(blue_function, x, y,t))
)

im.save(filename + str(t)+ '.png')
print 'done' + str(t)


if __name__ == '__main__':
Expand All @@ -193,7 +193,7 @@ def generate_art(filename, x_size=350, y_size=350):
# Create some computational art!
# TODO: Un-comment the generate_art function call after you
# implement remap_interval and evaluate_random_function
generate_art("example5.png", 350, 350)
generate_art("frame", 100, 100, 60)
# Test that PIL is installed correctly
# TODO: Comment or remove this function call after testing PIL install
# test_image("noise.png")