Skip to content
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

homework #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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 color-1199917597938236984-0.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 color-1207118258455156883-0.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 color-1276863559621402353-0.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 color-1744748725185646058-0.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 color-1894054633060196639-0.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 color-2156504193914335439-0.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 color-4810050495368163174-0.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 color-57909931272364174-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions favorite.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
4810050495368163174
make by entering python[3] create_art.py --seed=4810050495368163174

78 changes: 73 additions & 5 deletions random_art.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import cmath
import math
import random

from math import pi
# Your job is to create better version of create_expression and
# run_expression to create random art.
# Your expression should have a __str__() function defined for it.
Expand All @@ -8,10 +10,76 @@
def create_expression():
"""This function takes no arguments and returns an expression that
generates a number between -1.0 and 1.0, given x and y coordinates."""
expr1 = lambda x, y: (x + y)/2
expr2 = lambda x, y: (x - y)/2
expr3 = lambda x, y: x * y
return random.choice([expr1, expr2, expr3])
expr15 = lambda x: math.sin(pi*x)
expr14 = lambda x: math.cos(pi*x)
expr13 = lambda x: math.atan(x)
expr12 = lambda x: 1/(1+x) if x != -1 else 1

expr11 = lambda x: random.choice([x.real, x.imag])
expr10 = lambda x: abs(x)

expr9 = lambda x: cmath.asin(pi*x)
expr8 = lambda x: x*cmath.asinh(1j*x.real - x.imag)
expr7 = lambda x: (1j-x)*(1j+x) if x != -1j else 1/(1-x)
expr6 = lambda x: (1+x)/(1-x) if x !=1 else 1/(1+x)

ave = lambda x,y: (x+y)/2
unave = lambda x,y: (x-y)/2

expr5 = lambda x,y: (x+1j*y)*cmath.exp(1j*random.uniform(-.5,.5))
expr4 = lambda x,y: (x+y)/2
expr3 = lambda x,y: (x-y)/2
expr2 = lambda x,y: random.choice([x,y])
expr1 = lambda x,y: x*y

list_1 = [expr1, expr2, expr3, expr4, expr5] # real/complex, 2 -> 2
list_2 = [expr6, expr7, expr8, expr9] # real/complex 1 -> 1
list_3 = [expr12, expr13, expr14, expr15] # real 1 -> 1
reals = [expr10, expr11] # complex -> real, 1 -> 1


num_start = random.randint(1,10)
num_choices = random.randint(1,10)
num_real = random.randint(1,10)
start = []
choices = []
final = []

average = random.choice([ave, unave]) # averages or not...
real = random.choice(reals) # makes it real

for _ in range(num_start):
start.append((random.choice(list_1), random.choice(list_1)))

for _ in range(num_choices):
choices.append(random.choice(list_2))

for _ in range(num_real):
final.append(random.choice(list_3))




def returner(x, y):
start_x, start_y = x, y


for item1, item2 in start:
start_x, start_y = item1(start_x, start_y), item2(start_y, start_x)

num = average(start_x, start_y)

for item in choices:
num = item(num)

num = real(num)

for item in final:
num = item(num)

return num

return returner


def run_expression(expr, x, y):
Expand Down