Git Product home page Git Product logo

random-art's Introduction

Random Art

Description

Create art using Python's random module and math functions.

Objectives

Learning Objectives

After completing this assignment, you should understand:

  • Randomness
  • The Python random module
  • The sublime beauty of generated art

Performance Objectives

After completing this assignment, you should be able to:

  • Generate images with Python
  • Use randomness to construct new functions

Details

Deliverables

  • A Git repo called random-art containing at least:
    • README.md file explaining how to run your project
    • a requirements.txt file
    • a random_art module
    • Your favorite piece of art you made, plus instructions on how to replicate it.

Requirements

  • No PEP8 or Pyflakes warnings or errors

Normal Mode

You are going to make random art, inspired by random-art.org. This project comes with a file create_art.py. This file expects a module called random_art with two functions:

  • create_expression(): this function takes no arguments and returns an expression that will generate a number between -1.0 and 1.0, given x and y coordinates.

  • run_expression(expression, 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.

What's an expression?

I'm super-glad you asked! It is a way for you to create a formula for your random art. You can define it however you like. Perhaps it's just a function and run_expression just runs it. Maybe it's an abstract syntax tree and run_expression walks the tree and evaluates it. Maybe it's Python code in a string that you call eval on. You have to figure this part out, and it's one of the harder parts of this exercise.

What should my expression do?

The concrete thing it has to do is take an x and y value and return a new value between -1.0 and 1.0. That doesn't tell you why or how, though.

You should randomly construct an expression that uses sin, cos, and any other functions you want. sin and cos will definitely help you create patterns, but you should be creative. Look at other functions available to you and create your own functions for use.

How you randomly construct the expression is up to you. random.random() and random.choice() are both obvious ways to construct it, but you should look at all the different functions for random distributions and consider them.

random1

This image was created with the following expression:

sin(pi * sin(pi * sin(pi * (sin(pi * sin(pi * sin(pi * sin(pi *
    cos(pi * y))))) * cos(pi * sin(pi * cos(pi *
    avg(sin(pi * y), (x * x)))))))))

Notes

create_art.py takes several command-line parameters you may want to use.

  • --seed SEED sets the random seed to a particular number. This is great for being able to generate the same image more than once.

  • -n NUM or --number NUM sets how many images to create. NUM is 1 by default.

  • --gray or --color sets whether the image is in grayscale or color. Color is default.

Additional Resources

Credit

Modified from a "nifty assignment" from the annual SIGCSE meeting.

random-art's People

Contributors

cndreisbach avatar brundleflytelepod avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.