Make Your Own
Algorithmic Art
A Gentle Introduction to Creative Coding with P5js
Contents
Introduction
Prologue - Algorithmic Art?
Part 1 - First Building Blocks
Before We Get Started
First Things First - A Canvas
Creating A Canvas With Code
The setup() Section
The draw() Section
Our First Shape - A Circle
Fill Colour
Outline Stroke
Saving And Sharing Our Sketches
Worked Example: Ripples
More Shapes - Rectangles, Lines
Part 2 - Algorithmic Thinking
Randomness
Worked Example: Paint Drops
Repetition
Repetition - Using The Counter
A Loop Within a Loop
Worked Example: Splatter!
Part 3 - More Building Blocks
Mixing Colours
Translucent Shades
Worked Example: Metropolis
Functions - Reusable Code
Functions Made of Functions
The Sinuous Sine Wave
Natural Decay
Worked Example: Spirograph
- 1 -
3
7
13
15
20
29
31
32
35
44
46
50
57
65
75
77
87
98
109
118
133
153
155
170
177
201
217
229
250
266
Part 4 - More Algorithmic Fun
An Apparently Unhelpful Definition
The Mysterious Holocrux
Random Recursion
Worked Example: Tree Forms
Creative Chaos
Making A Map of Chaos
Worked Example: Whirling Dervish
Part 5 - Even More Building Blocks
A More Human Colour Model
Worked Example: Contemplation in Colour
Not So Random Randomness
Worked Example: Alien Terrain
Part 6 - Even More Algorithmic Adventures
Algorithms That Make Algorithms
Turtle Code
Growing Turtle Code
Worked Example: Fractured Reality
Epilogue - Algorithms As Art
Appendix A: More Loop Examples
Appendix B: Just Enough Trigonometry
Appendix C: A Bit About Complex Numbers
Gallery
- 2 -
299
301
302
318
325
350
374
394
407
409
424
435
449
469
471
471
487
502
519
521
533
543
559
Introduction
What’s Our Aim?
The aim of this guide is to inspire more people to create algorithmic art - and enjoy doing it!
To do that we’ll will gently introduce:
● The key ideas we need to create art with computers - like pixels, colour and shapes.
● How we tell our computers to draw and paint what we want - using a language that
computers can understand.
● Cool (but simple) mathematical ideas that help make amazing art - ideas like repetition,
randomness, recursion, and even something called chaos!
We’ll avoid lots of technical jargon and unnecessary equations. We won’t assume you know lots
of maths already, and you don’t need to have programmed a computer before at all.
We’ll keep things friendly and informal, start from the very basics and gently build up from there,
taking every opportunity to explain ideas visually and with lots of examples.
We don’t want to leave anyone behind!
If you work your way through this book, by the end you should:
● Be able to code confidently, and with enough knowledge of coding for it never to be a
barrier to any creative ideas you have.
● Have a good feel for a good range of algorithms and mathematical ideas that can be
used to create really interesting visual forms.
● Have had some hands-on experience of the process of creating algorithmic art, from
creative inspiration, experimenting and learning from failure, using mathematical tools to
solve problems, and refining a work to finalise a good composition.
Who Is This Book For?
This book is for anyone who is interested in art, computing or maths and wants to see how they
combine to create beautiful things!
This book was written for three communities in particular:
- 3 -
● Artists who have never coded before, and want to take their first steps.
● Technologists who may be able to code and want to explore their own artistic creativity.
● Teachers seeking a visual approach for teaching programming and algorithms.
If you’re a student of digital art, you will find this book helpful to get you started and confident
with coding, before progressing onto more advanced topics in your course.
How We’ll Work, And How We Won’t
This book is firmly aimed at beginners. For that reason, this book won’t go fast, and it won’t try
to be too concise.
We’ll introduce each new idea with a nice friendly chat, and use lots of pictures, analogies and
examples. Many of us prefer to learn visually, not by staring at a page of text.
As we discuss a topic, you’ll be encouraged to experiment with the examples and ideas we
come across. This hands-on work is really important. You can’t become a good artist without
practice and without trying new things. The same is true for coding. We learn by breaking
things, seeing what works and what doesn’t.
After each new idea, we’ll work through a small example project illustrating how that new idea
can be used. We’ll include all the steps and preparatory work, often unseen, to really
understand and experience how a work of algorithmic art is created.
Also, this isn’t a reference book. We won’t try to talk about everything related to coding or
algorithms. It’s a practical guide to get you started with algorithmic art, and give you enough
confidence to explore and continue learning, making use of the great online resources and
references yourself.
There’s one area of algorithmic art that we won’t cover in this book, and that’s animation.
Animation isn’t best explained in a book where the images on the page don’t move. We’ll cover
animation topics on the blog that accompanies this book.
Digital Art for A Digital Age
Over the centuries, as new materials, new science and new philosophical ideas have emerged,
artists haven’t been shy about adopting them. This digital age is no different.
Every aspect of our lives is massively and increasingly permeated by code, data and algorithms.
It would be increasingly impossible to avoid using these to create the art of our time. And artists
- 4 -
are increasingly using code, data and algorithms as their new tools and media. Some even
consider their algorithms as art, as their new means of expression.
Even if you’re not so interested in all that philosophical stuff, creating art with code, data and
algorithms is fun and exciting in ways that traditional art isn’t.
Programming? Processing? P5js? Coding?
If we want our computers to create art for us, we need to talk to them so we can tell them what
we want. We need to use a language that they can understand precisely and without ambiguity.
These languages are called computer programming languages. We can’t use our own
languages like English or Spanish because they’re not precise or unambiguous enough.
Processing is the name of the programming language that was designed to make creating art
with computers easy. And it worked. Processing has grown in popularity amongst algorithmic
artists, designers, creative technologists, and is increasingly taught in art schools and
universities. Because it’s so easy, and so visual, there is growing interest in using it to teach
children to program computers and to think algorithmically.
p5js is a version of Processing designed to work on the web. A web browser on a computer,
laptop, tablet or smartphone is all that’s needed to view and interact with art created with p5js.
That’s a powerful thing, because your audience could be any one of the three billion people on
the internet all over the world.
In this book we’ll not be too strict about distinguishing Processing from p5js, but whenever
something is unique to p5js we’ll say so.
Coding is just a modern term for programming. Decades ago scientists programmed the
computers that controlled space flight. Today artists do creative coding. It just sounds fresher!
Open Source Culture
All the software we’ll use is open source - which means it is free to get, change, and share. For
most people this means there is no need to pay for it, a great advantage if you’re a student on a
budget, or keeping an eye on costs teaching children to code.
More than just being cost-free, open source is a culture. It’s a culture of sharing what we’re
working on, encouraging others to use it, being generous with our skills and honest about things
that don’t work so well so others can have a go. The open source movement has created some
of the world’s best and most important technology - and all available to anyone without being
asked to pay.
We’ll also be making our art available on the web. The web is the most open and widely
accessible exhibition space in the world, open to people from many cultures and backgrounds,
- 5 -
using their own choice of technology to experience our creations, be that a cost-effective laptop
or a convenient smartphone.
All the art that we create in the book, together with the code to make it, will be freely available
on the internet for anyone to see, share and experiment with themselves.
Author’s Note
You can join in and discuss your questions or ideas online. A blog accompanying this book,
which also covers additional topics and questions raised by readers, is at:
● https://makeyourownalgorithmicart.blogspot.co.uk
You can also contact me by email makeyourownalgorithmicart@gmail.com or on Twitter
@algorithmic_art. I’d love to hear about what you’re working on, share what you’ve created
online, or talk about any problems you’re having with this book, coding or art in general.
And I really encourage you to join in with a local group interested in algorithmic art. Having a
community around you is part of the amazing experience of creating art with code. And if a
group doesn’t exist near you, go along to a related computing or art group and recruit friends to
start your own movement!
I run the mostly London based Algorithmic Art meetup, where you’re always welcome to come
along, share what you’re working on, find out what others are doing, and make new friends.
I will have failed as a teacher if any reader feels left behind because something in this book
wasn’t explained well enough. So do get in touch if this happens!
Have fun!
Tariq
- 6 -