Programmatic Art
The resources on this page were originally created by Dr. Aaron Bradley of Summit Middle School. I've done some reformatting to add clarity but that is about it. Enjoy!
|
One fun thing to do with graphics is to make programmatic art. When randomness is added, things get even more excited: you program an overall theme, but each execution of the program creates something new.
Consider the following program:
Consider the following program:
from sgfx import *
import random
w = Window()
colors = ['white', 'black']
# Create concentric circles whose colors are selected randomly.
for r in range(400, 0, -10):
w.circle(250, 250, r, color=random.choice(colors))
# Create 3D-looking circles at random places with random radii.
for i in range(20):
x = random.randint(0, 500)
y = random.randint(0, 500)
r = random.randint(0, 50)
w.circle(x, y, r, color='black')
w.circle(x+3, y+3, r, color='red')
w.run()
import random
w = Window()
colors = ['white', 'black']
# Create concentric circles whose colors are selected randomly.
for r in range(400, 0, -10):
w.circle(250, 250, r, color=random.choice(colors))
# Create 3D-looking circles at random places with random radii.
for i in range(20):
x = random.randint(0, 500)
y = random.randint(0, 500)
r = random.randint(0, 50)
w.circle(x, y, r, color='black')
w.circle(x+3, y+3, r, color='red')
w.run()
Each execution creates something a little different.
Here are some ideas to get you going on making your own programmatic art:
- Use for loops and randomness (especially random.randint(lo, hi) for choosing values between lo and hi) to create many instances of objects at random locations and with random dimensions.
- Use arrays of colors and random.choice(colors) to select colors randomly. More is not always better. My artwork, which is not too shabby, uses only three colors to good effect.
- Apply math: combining loop variables with polynomial functions works well, e.g.,
for i in range(10):
w.circle(10*i, 20*i, 10*i)