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 .DS_Store
Binary file not shown.
Binary file added 12.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 13.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 33.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 34.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 35.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 36.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 4.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 color0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 77 additions & 2 deletions random_art.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,94 @@
import random
from math import sin, cos, pi, tan, hypot, e

# 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.


def cube(a):
return a ** 3


def avg(x, y):
return x + y / 2


def wut(x, y):
return (x**10) + (y**3)


def wtf(x, y, z):
return (x**3) + (y**4) + (z**5)


def omg_wtf(prob):
return("wtf(" + str(generate_expression(prob**2)) + ','
+ str(generate_expression(prob**2)) + ','
+ str(generate_expression(prob**2)) + ")")


def wut_wut(prob):
return("wut(" + str(generate_expression(prob**2)) + ','
+ str(generate_expression(prob**2)) + ")")


def sin_pi(prob):
return "sin(pi*" + str(generate_expression(prob**2)) + ")"


def tan_pi(prob):
return "tan(pi*" + str(generate_expression(prob**2)) + ")"


def cube_pi(prob):
return "cube(pi*" + str(generate_expression(prob**2)) + ")"


def cos_pi(prob):
return "cos(pi*" + str(generate_expression(prob**2)) + ")"


def avg_num(prob):
return ("avg(" + str(generate_expression(prob**2)) + ','
+ str(generate_expression(prob**2)) + ")")


def hypot_num(prob):
return ("hypot(" + str(generate_expression(prob**2)) + ','
+ str(generate_expression(prob**2)) + ")")


def cos_num(prob):
return "cos(" + str(generate_expression(prob**2)) + ")"


def sin_num(prob):
return "sin(" + str(generate_expression(prob**2)) + ")"


def cube_num(prob):
return "cube(" + str(generate_expression(prob**2)) + ")"


def generate_expression(prob=0.99):
if random.random() < prob:
return random.choice([sin_pi(prob), cos_pi(prob),
sin_num(prob), avg_num(prob),
omg_wtf(prob)])
else:
return random.choice(['x', 'y'])


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."""
expr = lambda x, y: (random.random() * 2) - 1
expr = generate_expression()
return expr


def run_expression(expr, x, y):
"""This function takes an expression created by create_expression and
an x and y value. It runs the expression, passing the x and y values
to it and returns a value between -1.0 and 1.0."""
return expr(x, y)
return eval(expr)
Binary file added twindemons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.