Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Project #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 RecursiveArtReflection.odt
Binary file not shown.
Binary file added RecursiveArtReflection.pdf
Binary file not shown.
Binary file added myart.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 myart1.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 myart2.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 myart3.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 myart4.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 myart5.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 modified noise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 56 additions & 16 deletions recursive_art.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""TODO: Put your header comment here."""

import math
import random
from PIL import Image

possibilites = ['x','y','prod','avg','cos_pi','sin_pi','neg','cbd']

def build_random_function(min_depth, max_depth):
"""Build a random function.
Expand All @@ -20,9 +21,20 @@ 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

if min_depth<=1:

Choose a reason for hiding this comment

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

These conditionals are a bit confusing - you could make them less so by adding an empty line between the separate statements (after lines 30 and 32) and commenting what exactly this portion of the code is doing.

rand = random.randint(0,1)
elif max_depth > 1:
rand = random.randint(2,7)
else:
rand = random.randint(4,7)
if rand==2 or rand==3:
return [possibilites[rand],build_random_function(min_depth-1,max_depth-1),build_random_function(min_depth-1,max_depth-1)]
if rand==0 or rand==1:
return [possibilites[rand]]
else:
return [possibilites[rand],build_random_function(min_depth-1,max_depth-1)]
#print(build_random_function(3,5))

Choose a reason for hiding this comment

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

Delete unused print statements before submitting code.


def evaluate_random_function(f, x, y):
"""Evaluate the random function f with inputs x,y.
Expand All @@ -43,10 +55,29 @@ 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] == 'prod':
return evaluate_random_function(f[1],x,y)*evaluate_random_function(f[2],x,y)
elif f[0] == 'avg':
return (evaluate_random_function(f[1],x,y)+evaluate_random_function(f[2],x,y))*.5
elif f[0] == 'cos_pi':
return math.cos(math.pi*evaluate_random_function(f[1],x,y))
elif f[0] == 'sin_pi':
return math.sin(math.pi*evaluate_random_function(f[1],x,y))
elif f[0] == 'neg':
return -1*evaluate_random_function(f[1],x,y)
elif f[0] == 'cbd':
return (evaluate_random_function(f[1],x,y))**3
else:
return evaluate_random_function(f[0],x,y)
# print(f[0])
# raise Exeption('unreconized function')
# jumble = build_random_function(3,5)
# print(jumble)
# print(evaluate_random_function(jumble,.5,.5))
def remap_interval(val,
input_interval_start,
input_interval_end,
Expand Down Expand Up @@ -80,10 +111,18 @@ def remap_interval(val,
>>> remap_interval(5, 4, 6, 1, 2)
1.5
"""
# TODO: implement this
pass


input_range = (input_interval_end - input_interval_start)
output_range = (output_interval_end - output_interval_start)
input_center = (input_interval_end + input_interval_start)/2
output_center = (output_interval_end + output_interval_start)/2
scale = abs(output_range / input_range)
# print("input_range ",input_range)

Choose a reason for hiding this comment

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

Delete commented out print statements.

# print("output_range ",output_range)
# print("input_center ",input_center)
# print("output_center ",output_center)
return ((val-input_center)*scale)+output_center

# print(remap_interval(0.5, 0, 1, 0, 10))
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 +176,10 @@ 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(12,15)
# print(red_function)
green_function = [build_random_function(13,17)]
blue_function = [build_random_function(20,25)]

# Create image and loop over all pixels
im = Image.new("RGB", (x_size, y_size))
Expand All @@ -164,8 +204,8 @@ 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("myart.png")
generate_art("myart6.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")