diff --git a/Reflection.pdf b/Reflection.pdf new file mode 100644 index 0000000..ea7a8ac Binary files /dev/null and b/Reflection.pdf differ diff --git a/all_art/myart.png b/all_art/myart.png new file mode 100644 index 0000000..b13295e Binary files /dev/null and b/all_art/myart.png differ diff --git a/all_art/myart1.png b/all_art/myart1.png new file mode 100644 index 0000000..e9588ff Binary files /dev/null and b/all_art/myart1.png differ diff --git a/all_art/myart10.png b/all_art/myart10.png new file mode 100644 index 0000000..c672e50 Binary files /dev/null and b/all_art/myart10.png differ diff --git a/all_art/myart11.png b/all_art/myart11.png new file mode 100644 index 0000000..956d96c Binary files /dev/null and b/all_art/myart11.png differ diff --git a/all_art/myart12.png b/all_art/myart12.png new file mode 100644 index 0000000..25514e0 Binary files /dev/null and b/all_art/myart12.png differ diff --git a/all_art/myart13.png b/all_art/myart13.png new file mode 100644 index 0000000..37c7002 Binary files /dev/null and b/all_art/myart13.png differ diff --git a/all_art/myart14.png b/all_art/myart14.png new file mode 100644 index 0000000..4ea4532 Binary files /dev/null and b/all_art/myart14.png differ diff --git a/all_art/myart15.png b/all_art/myart15.png new file mode 100644 index 0000000..9622b32 Binary files /dev/null and b/all_art/myart15.png differ diff --git a/all_art/myart16.png b/all_art/myart16.png new file mode 100644 index 0000000..d3ace83 Binary files /dev/null and b/all_art/myart16.png differ diff --git a/all_art/myart17.png b/all_art/myart17.png new file mode 100644 index 0000000..2e1a780 Binary files /dev/null and b/all_art/myart17.png differ diff --git a/all_art/myart18.png b/all_art/myart18.png new file mode 100644 index 0000000..c6e6f11 Binary files /dev/null and b/all_art/myart18.png differ diff --git a/all_art/myart19.png b/all_art/myart19.png new file mode 100644 index 0000000..a43d7cd Binary files /dev/null and b/all_art/myart19.png differ diff --git a/all_art/myart2.png b/all_art/myart2.png new file mode 100644 index 0000000..ecc1af2 Binary files /dev/null and b/all_art/myart2.png differ diff --git a/all_art/myart20.png b/all_art/myart20.png new file mode 100644 index 0000000..95e0925 Binary files /dev/null and b/all_art/myart20.png differ diff --git a/all_art/myart21.png b/all_art/myart21.png new file mode 100644 index 0000000..6fa9528 Binary files /dev/null and b/all_art/myart21.png differ diff --git a/all_art/myart3.png b/all_art/myart3.png new file mode 100644 index 0000000..0152f3b Binary files /dev/null and b/all_art/myart3.png differ diff --git a/all_art/myart4.png b/all_art/myart4.png new file mode 100644 index 0000000..864748b Binary files /dev/null and b/all_art/myart4.png differ diff --git a/all_art/myart5.png b/all_art/myart5.png new file mode 100644 index 0000000..b290c51 Binary files /dev/null and b/all_art/myart5.png differ diff --git a/all_art/myart6.png b/all_art/myart6.png new file mode 100644 index 0000000..e6a521c Binary files /dev/null and b/all_art/myart6.png differ diff --git a/all_art/myart7.png b/all_art/myart7.png new file mode 100644 index 0000000..194d1fa Binary files /dev/null and b/all_art/myart7.png differ diff --git a/all_art/myart8.png b/all_art/myart8.png new file mode 100644 index 0000000..0475d26 Binary files /dev/null and b/all_art/myart8.png differ diff --git a/all_art/myart9.png b/all_art/myart9.png new file mode 100644 index 0000000..bcde792 Binary files /dev/null and b/all_art/myart9.png differ diff --git a/all_art/noise.png b/all_art/noise.png new file mode 100644 index 0000000..65f7c54 Binary files /dev/null and b/all_art/noise.png differ diff --git a/example1.png b/example1.png new file mode 100644 index 0000000..c6e6f11 Binary files /dev/null and b/example1.png differ diff --git a/example2.png b/example2.png new file mode 100644 index 0000000..194d1fa Binary files /dev/null and b/example2.png differ diff --git a/example3.png b/example3.png new file mode 100644 index 0000000..bcde792 Binary files /dev/null and b/example3.png differ diff --git a/noise.png b/noise.png deleted file mode 100644 index 5574db7..0000000 Binary files a/noise.png and /dev/null differ diff --git a/recursive_art.py b/recursive_art.py index 6292170..8d444ad 100644 --- a/recursive_art.py +++ b/recursive_art.py @@ -1,6 +1,7 @@ """TODO: Put your header comment here.""" import random +import math from PIL import Image @@ -20,8 +21,26 @@ 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: # to get a variable depth, + rand = random.randint(0, max_depth - min_depth) # pick an int between 0 and the diff of max and min depth - this is how many times you will keep going + if rand == 0: # if 0, stop here + rand = random.randint(0, 1) + if rand == 0: + return ["x"] + return ["y"] + if max_depth == 1: # if max depth gets to 1, stop here + rand = random.randint(0, 1) + if rand == 0: + return ["x"] + return ["y"] + func = [ "prod", "avg", "cos_pi", "sin_pi", "cube", "sin_5pi"] + rand = random.randint(0, len(func) - 1) + chosenfunc = func[rand] + + # make sure to pass function two arguments if it needs it + if chosenfunc == "prod" or chosenfunc == "avg": + return [chosenfunc, build_random_function(min_depth - 1, max_depth - 1), build_random_function(min_depth - 1, max_depth - 1)] + return [chosenfunc, build_random_function(min_depth - 1, max_depth - 1) ] def evaluate_random_function(f, x, y): @@ -42,10 +61,38 @@ def evaluate_random_function(f, x, y): -0.5 >>> evaluate_random_function(["y"],0.1,0.02) 0.02 + >>> evaluate_random_function( ["sin_pi", ["x"]], 0.0, 0.3) + 0.0 + >>> evaluate_random_function( ["cos_pi", ["y"]], 0.3, 0.0) + 1.0 + >>> evaluate_random_function(["cos_pi", ["sin_pi", ["x"]]], 0.0, 0.3) + 1.0 + >>> evaluate_random_function(["prod", ["x"], ["y"]], 0.1, 0.5) + 0.05 + >>> evaluate_random_function(["avg", ["x"], ["y"]], 0.2, 0.5) + 0.35 + >>> evaluate_random_function(["cube", ["y"]], 0.1, -1.0) + -1.0 + >>> evaluate_random_function( ["sin_5pi", ["x"]], 0.078, 0.8) + 0.9408807689542255 """ - # TODO: implement this - pass - + fname = f[0] + if fname == "x": + return x + if fname == "y": + return y + if fname == "sin_pi": + return math.sin( math.pi * evaluate_random_function(f[1], x, y) ) + if fname == "cos_pi": + return math.cos( math.pi * evaluate_random_function(f[1], x, y) ) + if fname == "prod": + return evaluate_random_function(f[1], x, y) * evaluate_random_function(f[2], x, y) + if fname == "avg": + return 0.5 * (evaluate_random_function(f[1], x, y) + evaluate_random_function(f[2], x, y)) + if fname == "cube": + return evaluate_random_function(f[1], x, y) ** 3 + if fname == "sin_5pi": + return math.sin( math.pi * 5 * evaluate_random_function(f[1], x, y) ) def remap_interval(val, input_interval_start, @@ -80,8 +127,14 @@ def remap_interval(val, >>> remap_interval(5, 4, 6, 1, 2) 1.5 """ - # TODO: implement this - pass + input_interval_length = input_interval_end - input_interval_start + output_interval_length = output_interval_end - output_interval_start + + val_in = val - input_interval_start + + input_pos = val_in/input_interval_length + output_pos = input_pos * output_interval_length + return output_interval_start + output_pos def color_map(val): @@ -137,9 +190,18 @@ 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"] + + min_depth = 2 + max_depth = 9 + + red_function = build_random_function(min_depth, max_depth) + print("RED: ", red_function) + green_function = build_random_function(min_depth, max_depth) + print("GREEN: ", green_function) + blue_function = build_random_function(min_depth, max_depth) + print("BLUE: ", blue_function) + + # Create image and loop over all pixels im = Image.new("RGB", (x_size, y_size)) @@ -161,11 +223,9 @@ def generate_art(filename, x_size=350, y_size=350): import doctest doctest.testmod() + # 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("myart21.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")