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 added ProjectReflection.pdf
Binary file not shown.
Binary file added example1.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 example2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 52 additions & 18 deletions recursive_art.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""TODO: Put your header comment here."""
"""
Victor Bianchi - Software Design - Fall 2017
MiniProject 2 : Computational Art
"""

import random
from random import randint
import math
from math import cos, sin, tan, pi
from PIL import Image


Expand All @@ -20,9 +26,25 @@ def build_random_function(min_depth, max_depth):
(See the assignment writ-eup for details on the representation of
these functions)
"""
# TODO: implement this
pass

building_blocks = ['x','y','cos_pi','sin_pi','prod','avg','tan_pi','substract',]
pick = random.choice(building_blocks)
i = random.randint(min_depth, max_depth)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like random_depth would be a more appropriate variable name. i does not give you any semantic information about the variable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I don't see you using it anywhere else in the code.


if max_depth <= 1:
return [random.choice(['x','y','t'])]

elif pick == 'cos_pi':
return ['cos_pi', build_random_function(min_depth-1, max_depth-1)]
elif pick == 'sin_pi':
return ['sin_pi', build_random_function(min_depth-1, max_depth-1)]
elif pick == 'tan_pi':
return ['tan_pi', build_random_function(min_depth-1, max_depth-1)]
elif pick == 'prod':
return ['prod', build_random_function(min_depth-1, max_depth-1), build_random_function(min_depth-1, max_depth-1)]
elif pick == 'avg':
return ['avg', build_random_function(min_depth-1, max_depth-1), build_random_function(min_depth-1, max_depth-1)]
elif pick == 'substract':
return ['substract', build_random_function(min_depth-1, max_depth-1), build_random_function(min_depth-1, max_depth-1)]

def evaluate_random_function(f, x, y):
"""Evaluate the random function f with inputs x,y.
Expand All @@ -43,9 +65,23 @@ def evaluate_random_function(f, x, y):
>>> evaluate_random_function(["y"],0.1,0.02)
0.02
"""
# TODO: implement this
pass

if f[0] == 'x':
return x
elif f[0] == 'y':
return y
elif f[0] == 'avg':
return 0.5 (evaluate_random_function(f[1],x,y) + evaluate_random_function(f[2],x,y))
elif f[0] == 'prod':
return (evaluate_random_function(f[1],x,y) * evaluate_random_function(f[2],x,y))
elif f[0] == 'substract':
return (evaluate_random_function(f[1],x,y) - evaluate_random_function(f[2],x,y))
elif f[0] == 'sin_pi':
return math.sin(math.pi*evaluate_random_function(f[1],x,y))
elif f[0] == 'tan_pi':
return math.tan(math.pi*evaluate_random_function(f[1],x,y))
elif f[0] == 'cos_pi':
return math.cos(math.pi*evaluate_random_function(f[1],x,y))

def remap_interval(val,
input_interval_start,
Expand Down Expand Up @@ -80,9 +116,9 @@ def remap_interval(val,
>>> remap_interval(5, 4, 6, 1, 2)
1.5
"""
# TODO: implement this
pass

output_val = input_interval_end - input_interval_start

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be useful to add more unit tests for this function, just to confirm that it works for all ranges.

input_val = output_interval_end - output_interval_start
return ((float(val - input_interval_start) * (input_val) / output_val)) + output_interval_start

def color_map(val):
"""Maps input value between -1 and 1 to an integer 0-255, suitable for use as an RGB color code.
Expand Down Expand Up @@ -137,9 +173,9 @@ def generate_art(filename, x_size=350, y_size=350):
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 = ["x"]
green_function = ["y"]
blue_function = ["x"]
red_function = build_random_function(7, 9)
green_function = build_random_function(7, 9)
blue_function = build_random_function(7, 9)

# Create image and loop over all pixels
im = Image.new("RGB", (x_size, y_size))
Expand All @@ -159,13 +195,11 @@ def generate_art(filename, x_size=350, y_size=350):

if __name__ == '__main__':
import doctest
doctest.testmod()
#doctest.testmod(verbose = True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove comments for your final submission


# Create some computational art!
# TODO: Un-comment the generate_art function call after you
# implement remap_interval and evaluate_random_function
# generate_art("myart.png")
#generate_art("example1.png")
#generate_art("example2.png")

# Test that PIL is installed correctly
# TODO: Comment or remove this function call after testing PIL install
test_image("noise.png")
#test_image("noise.png")