-
Notifications
You must be signed in to change notification settings - Fork 15
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
Turning in MP2 #12
Open
Subeen-Kim
wants to merge
3
commits into
sd17fall:master
Choose a base branch
from
Subeen-Kim:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Turning in MP2 #12
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"source": [ | ||
"From a process point of view, what went well? What could you improve? Other possible reflection topics: Was your project appropriately scoped? Did you have a good plan for unit testing? How will you use what you learned going forward? What do you wish you knew before you started that would have helped you succeed?\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"I tried several testing for appropriate moments whenever I added further implementation. Also I used doctest by making example tests myself. Before this miniproject, I knew the concept of the recursion, whereas I was not used to it. After this miniproject, I get used to the recursion as well as I learned when I should use the recursion.\n", | ||
"\n", | ||
"Also it was nice to use \"import random\", and \"import math\" by searching the proper function myself." | ||
] | ||
} | ||
], | ||
"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 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""TODO: Put your header comment here.""" | ||
|
||
import random | ||
import math | ||
from PIL import Image | ||
|
||
|
||
|
@@ -20,9 +21,69 @@ 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 | ||
|
||
depth = random.randint(min_depth, max_depth) | ||
|
||
seed_function = [] | ||
seed_generation = 2**depth | ||
|
||
for i in range(seed_generation): | ||
xory_number = random.randint(1,2) | ||
|
||
if xory_number == 1: | ||
seed_function.append(["x"]) | ||
|
||
if xory_number == 2: | ||
seed_function.append(["y"]) | ||
|
||
transient_function = seed_function | ||
|
||
while depth > 0: | ||
|
||
resulting_function = [] | ||
seed_index = 0 | ||
|
||
for i in range(2**(depth-1)): | ||
function_number = random.randint(3,8) | ||
|
||
if function_number == 3: | ||
chunk = ["cos_pi"] | ||
chunk.append(transient_function[seed_index]) | ||
seed_index += 1 | ||
|
||
elif function_number == 4: | ||
chunk = ["sin_pi"] | ||
chunk.append(transient_function[seed_index]) | ||
seed_index += 1 | ||
|
||
elif function_number == 5: | ||
chunk = ["prod"] | ||
chunk.append(transient_function[seed_index]) | ||
chunk.append(transient_function[seed_index+1]) | ||
seed_index += 2 | ||
|
||
elif function_number == 6: | ||
chunk = ["avg"] | ||
chunk.append(transient_function[seed_index]) | ||
chunk.append(transient_function[seed_index+1]) | ||
seed_index += 2 | ||
|
||
elif function_number == 7: | ||
chunk = ["abs"] | ||
chunk.append(transient_function[seed_index]) | ||
seed_index += 1 | ||
|
||
elif function_number == 8: | ||
chunk = ["cubic"] | ||
chunk.append(transient_function[seed_index]) | ||
seed_index += 1 | ||
|
||
resulting_function.append(chunk) | ||
|
||
transient_function = resulting_function | ||
depth = depth - 1 | ||
|
||
return resulting_function[0] | ||
|
||
def evaluate_random_function(f, x, y): | ||
"""Evaluate the random function f with inputs x,y. | ||
|
@@ -42,9 +103,34 @@ def evaluate_random_function(f, x, y): | |
-0.5 | ||
>>> evaluate_random_function(["y"],0.1,0.02) | ||
0.02 | ||
>>> evaluate_random_function(["prod", ["x"], ["sin_pi", ["prod", ["x"], ["y"]]]], 1, 0) | ||
0.0 | ||
""" | ||
# TODO: implement this | ||
pass | ||
|
||
if f[0] == "x": | ||
return x | ||
|
||
elif f[0] == "y": | ||
return y | ||
|
||
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] == "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))/2 | ||
|
||
elif f[0] == "abs": | ||
return math.fabs(evaluate_random_function(f[1],x,y)) | ||
|
||
elif f[0] == "cubic": | ||
return (evaluate_random_function(f[1],x,y))**3 | ||
|
||
|
||
|
||
def remap_interval(val, | ||
|
@@ -80,8 +166,7 @@ def remap_interval(val, | |
>>> remap_interval(5, 4, 6, 1, 2) | ||
1.5 | ||
""" | ||
# TODO: implement this | ||
pass | ||
return (output_interval_end - output_interval_start)*(val - input_interval_start)/(input_interval_end - input_interval_start) + output_interval_start | ||
|
||
|
||
def color_map(val): | ||
|
@@ -105,6 +190,7 @@ def color_map(val): | |
""" | ||
# NOTE: This relies on remap_interval, which you must provide | ||
color_code = remap_interval(val, -1, 1, 0, 255) | ||
|
||
return int(color_code) | ||
|
||
|
||
|
@@ -137,9 +223,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)) | ||
|
@@ -159,12 +245,14 @@ def generate_art(filename, x_size=350, y_size=350): | |
|
||
if __name__ == '__main__': | ||
import doctest | ||
doctest.testmod() | ||
# doctest.testmod() | ||
# doctest.testmod(verbose=True) | ||
doctest.run_docstring_examples(evaluate_random_function, globals(), verbose=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may need to remove unnecessary commented code when submitting |
||
|
||
# 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("myart7.png") | ||
|
||
# Test that PIL is installed correctly | ||
# TODO: Comment or remove this function call after testing PIL install | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you did quite a good job with not using recursion.
However, sometimes using recursion might make code more concise.
I have one suggestion for the variable names - Use 'root' for initial node for the graph, use 'temp' instead of 'transient'. The name 'seed' is usually used for fixing randomness of random functions.