A Python project – Generative graphics in Python
Lesson 9 of 15 · Python projects
A more detailed version:
The same example (random circles) and more is in the lesson Generative art. See: Generative art.
The same example (random circles) and more is in the lesson Generative art. See: Generative art.
In this project we will learn how to make generative graphics using Processing Python Mode.
Generative graphics is a kind of digital art in which a program automatically generates visual shapes using algorithms and random values.
In this project you will learn:
- how to draw shapes on the screen
- how to use random values
- how to make a generative visual pattern
- how to make creative graphics programs
An example of generative graphics
The program will randomly draw circles of different colours and sizes on the screen.
The program code
def setup():
size(600,400)
background(255)
def draw():
x = random(width)
y = random(height)
r = random(10,50)
fill(random(255), random(255), random(255),150)
ellipse(x,y,r,r)
How this code works
- random() generates random values
- ellipse() draws a circle on the screen
- fill() sets the colour of the shape
- every frame draws a new circle
Every time you run the program,
you get a completely different picture.
Possible improvements to the project
- draw squares or triangles
- add animation to the shapes
- make symmetrical patterns
- save the generated picture
Related lessons
Next project
How to make the project your own:
1) first run the given code without changes, 2) change one thing and predict what will happen, 3) add at least one feature of your own, 4) write down in a notebook what you changed and why. A work log like that is the basis of a creative programming paper.
1) first run the given code without changes, 2) change one thing and predict what will happen, 3) add at least one feature of your own, 4) write down in a notebook what you changed and why. A work log like that is the basis of a creative programming paper.
