-
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
Computational Art Project-Shreya Rangarajan #9
Open
srangar03
wants to merge
1
commit into
sd17fall:master
Choose a base branch
from
srangar03: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
Changes from all commits
Commits
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
Binary file not shown.
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,5 +1,10 @@ | ||
"""TODO: Put your header comment here.""" | ||
""" | ||
Created on Mon Sep 25 2017 | ||
Computational Art Mini Progject | ||
|
||
@author: Shreya Rangarajan | ||
""" | ||
import math | ||
import random | ||
from PIL import Image | ||
|
||
|
@@ -20,8 +25,31 @@ 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 | ||
random_list = ["prod", "avg", "cos_pi", "sin_pi"] | ||
random_func = random.choice(random_list) | ||
if max_depth > 0: | ||
if min_depth > 0: | ||
if random_func == "prod" or random_func == "avg": | ||
return [random_func, build_random_function(min_depth-1, max_depth-1), build_random_function(min_depth-1, max_depth-1)] | ||
else: | ||
return [random_func, build_random_function(min_depth-1, max_depth-1)] | ||
else: | ||
random_list += ["x", "y"] | ||
random_func = random.choice(random_list) | ||
if random_func == "prod" or random_func == "avg": | ||
return [random_func, build_random_function(min_depth-1, max_depth-1), build_random_function(min_depth-1, max_depth-1)] | ||
elif random_func == "cos_pi" or random_func == "sin_pi": | ||
return [random_func, build_random_function(min_depth-1, max_depth-1)] | ||
else: | ||
if random.randint(0,1) == 1: | ||
return "y" | ||
else: | ||
return "x" | ||
else: | ||
if random.randint(0,1) == 1: | ||
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 could use |
||
return "y" | ||
else: | ||
return "x" | ||
|
||
|
||
def evaluate_random_function(f, x, y): | ||
|
@@ -43,9 +71,18 @@ def evaluate_random_function(f, x, y): | |
>>> evaluate_random_function(["y"],0.1,0.02) | ||
0.02 | ||
""" | ||
# TODO: implement this | ||
pass | ||
|
||
if f[0] == "prod": | ||
return evaluate_random_function(f[1], x, y) * evaluate_random_function(f[2], x, y) | ||
if f[0] == "avg": | ||
return 0.5 * (evaluate_random_function(f[1], x, y) + evaluate_random_function(f[2], x, y)) | ||
if f[0] == "cos_pi": | ||
return math.cos(math.pi * evaluate_random_function(f[1], x, y)) | ||
if f[0] == "sin_pi": | ||
return math.sin(math.pi * evaluate_random_function(f[1], x, y)) | ||
if f[0] == "x": | ||
return x | ||
if f[0] == "y": | ||
return y | ||
|
||
def remap_interval(val, | ||
input_interval_start, | ||
|
@@ -80,9 +117,17 @@ def remap_interval(val, | |
>>> remap_interval(5, 4, 6, 1, 2) | ||
1.5 | ||
""" | ||
# TODO: implement this | ||
pass | ||
a = float(val) | ||
b = float(input_interval_start) | ||
c = float(input_interval_end) | ||
d = float(output_interval_start) | ||
e = float(output_interval_end) | ||
|
||
first_val = abs((a-b)/(c-b)) | ||
second_val = e-d | ||
remap = first_val * second_val + d | ||
|
||
return remap | ||
|
||
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 +182,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(4,10) | ||
green_function = build_random_function(4,10) | ||
blue_function = build_random_function(4,10) | ||
|
||
# Create image and loop over all pixels | ||
im = Image.new("RGB", (x_size, y_size)) | ||
|
@@ -164,8 +209,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("myart.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") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
This is a giant conditional. There's nothing necessarily "wrong" with nesting conditionals this deep, but I've found that once you reach three layers of if statements it's probably best to sit back and try to understand why you need to do that, because chances are you can refactor it to be more readable. Adding comments explaining what you are doing helps as well.