-
Notifications
You must be signed in to change notification settings - Fork 15
Pull request #14
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
base: master
Are you sure you want to change the base?
Pull request #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
|
|
||
|
|
@@ -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) | ||
|
|
||
| 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. | ||
|
|
@@ -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, | ||
|
|
@@ -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 | ||
|
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. 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. | ||
|
|
@@ -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)) | ||
|
|
@@ -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) | ||
|
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. 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") | ||
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.
something like
random_depthwould be a more appropriate variable name.idoes not give you any semantic information about the variable.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.
but I don't see you using it anywhere else in the code.