Computer Generated Art #thisismyclassroom #programming #steam

Screen Shot 2016-03-31 at 02.22.22

I wanted to create a task that allowed students to create a computer program in Python that would automatically create its own artwork but be customisable so that each student could experiment and personalise their own program to their tastes.

Screen Shot 2016-03-31 at 02.15.10

It’s a rough Python 3 program using the Turtle library and an array of Turtles but so far it has produced some really nice work. In the images shown below the program uses a user-defined function that draws a randomly sized square. I thought this would be easy for the students to understand and hack into something new!

Screen Shot 2016-03-31 at 02.15.24

Of course art can be created as a response to an external stimulus so a possible extension of this program would be to get input from the user (colours, mood, age) or calculate a range of colours from an input sensor or device (temperature, time, image).

Screen Shot 2016-03-31 at 02.15.38

The code is below! Any suggestions or improvements would be appreciated!

import turtle
import random
wn = turtle.Screen()
w = wn.window_width()
h = wn.window_height()

t1 = turtle.Turtle()
t2 = turtle.Turtle()
t3 = turtle.Turtle()
t4 = turtle.Turtle()
t5 = turtle.Turtle()
t6 = turtle.Turtle()

turtles = [t1, t2, t3, t4, t5, t6]

def square(item, size):
for x in range(4):
item.forward(size)
item.right(90)
item.forward(size)
item.left(random.randrange(-180, 180))

wn.tracer(False)
for iteration in range(3):
for item in turtles:
item.penup()
item.goto(random.randrange(-w,w),random.randrange(-h,h))
item.color(random.randrange(0,255)/255.,random.randrange(0,255)/255.,random.randrange(0,255)/255.)
item.pendown()
wn.tracer(False)
for move in range(2500):
for item in turtles:
item.speed(0)
square(item,random.randrange(5,25))
wn.tracer(True)

wn.exitonclick()

Screen Shot 2016-03-31 at 02.51.34

Screen Shot 2016-03-31 at 02.54.57