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 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.
32 changes: 32 additions & 0 deletions Reflection.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This project was extremely interesting and fun as we are generating images from ramdon functions we generated. Despite of my limited knowledge on color's organization, I was able to understand the project and gained a little insight on color. This project made a very effective use of recursion. From a process point of view, all doctests went pretty well as I was able to implement unit test and test out each individual function making sure it works. In addition to that, writing the definition of the function itelf is a very fun process. For example, for the remap_interval function, I did the entire math process on paper first, then transform it to computer science. When I was doing the project, I realized that coding is more complex than math as we have to think about many different situations as well as certain conditions, such as base case. Often in times, I do not think of particular scenario that could impact my result. One thing i wish I knew before I started that would helped me succeed was the science on color. I started the project slowly as I was confused by the concept of color. I followed the instructions step by step. If I knew a little more about it, I could just use my own knowledge to write codes to test out my skills. "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
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.
62 changes: 46 additions & 16 deletions recursive_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import random
from PIL import Image

import math

def build_random_function(min_depth, max_depth):
"""Build a random function.
Expand All @@ -20,8 +20,21 @@ 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
function = ['prod','avg','cos_pi','sin_pi','tan_pi','square']

if(min_depth < 1):
if(random.randint(0, 1) == 1):
return ['x']
return ['y']
if(max_depth == 0):
if(random.randint(0, 1) == 1):
return ['x']
return ['y']
choice = random.randint(0, len(function) - 1)
if(choice > 4):

Choose a reason for hiding this comment

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

it would be easier to understand the code if you put an inline comment explaining why you made this choice.

return [function[choice], build_random_function(min_depth - 1, max_depth - 1)]
return [function[choice], 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):
Expand All @@ -43,8 +56,24 @@ def evaluate_random_function(f, x, y):
>>> evaluate_random_function(["y"],0.1,0.02)
0.02
"""
# TODO: implement this
pass
if len(f)==1:

Choose a reason for hiding this comment

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

I recommend that you add one or two unit tests of your own to test the function.

if f[0]=="x":
return x
else:
return y
else:
if 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))*0.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] == 'tan_pi'):
return math.tan(math.pi * evaluate_random_function(f[1], x, y))
elif(f[0] == 'square'):
return (evaluate_random_function(f[1], x, y)**2)


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

return output_interval_start + scale*(output_interval_end - 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 +166,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(10, 15)
green_function = build_random_function(7, 10)
blue_function = build_random_function(9, 13)

# Create image and loop over all pixels
im = Image.new("RGB", (x_size, y_size))
Expand All @@ -157,15 +186,16 @@ def generate_art(filename, x_size=350, y_size=350):
im.save(filename)


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

Choose a reason for hiding this comment

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

please remove these comments for you final code submission

# doctest.testmod()
# # doctest.run_docstring_examples(evaluate_random_function,globals(), verbose=True)

# 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("example2.png")

# Test that PIL is installed correctly
# # Test that PIL is installed correctly

Choose a reason for hiding this comment

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

please remove these comments for you final code submission

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