A library for creative coding and generative art.
Our team makes each part of the build phase seamless with regular check-ins and deliverables.
It's time to take the product live - the end if the build phase but the beginning of being in market.
Historically, processing came first. Processing was created in 2001 as a Java-based environment specifically designed for artists, designers, and educators to explore creative coding. Since it was a standalone program, it required installation on a user's computer.
p5.js, on the other hand, emerged in 2014 as a JavaScript library. This offered a significant advantage in terms of accessibility. By leveraging JavaScript, p5.js could run within a web browser, eliminating the installation step and allowing creations to be shared online more easily.
In a nutshell, Processing and P5JS provide the same features. P5JS is easier to learn however (imo) because JavaScript is just a more lenient programming language.
For example, JavaScript is not a strongly typed language.
Everything you can do in P5JS you can also do without P5JS via HTML's canvas API. P5 basically uses the Canvas API functions under the hood and creates wrappers around them.
There's extensive documentation about the Canvas API on the MDN web docs. Overall P5 is just much more beginner friendly and provides some useful extras however.
Processing and P5 aren't just software libraries but it's actually a big foundation currently that takes care of developing the language further.
Creative coding is where programming meets artistic expression. Instead of writing code to build websites or apps, you use code to create visual art, animations, music, and even interactive experiences.
Generative art is art created with the help of a system, often a computer program or algorithm, that acts somewhat independently. It's like the artist sets the rules, and the system creates the art within those guidelines, sometimes with an element of randomness.
It's kind of similar to codepen if you're familiar with it. | Link to P5 Editor
Sketch Running live in an iFrame
You can simply include via a script tag in your HTML file (either a hosted version or a local version):
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.4/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.4/addons/p5.sound.min.js">
</script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<main>
</main>
<script src="sketch.js"></script>
</body>
</html>
There's also other library compatible versions out there. So you could actually import p5 in a codepen and make a sketch there as well.
Overview of the setup() and draw() functions and how to create the canvas.
Additional info on styling with CSS.
Drawing basic shapes, polygons, styling and coloring them.
Drawing Stack.
How to make something animated.
The setup and draw functions are the two main components of every P5 program.
The noLoop() function can be placed in the draw() function to stop its execution at any point.
The preLoad() function is run even before the setup() function and is used to load in assets or query APIs in an asynchronous manner. It waits for those calls to finish before resuming with setup(). setup() and draw() can't wait for async calls.
As its name suggests the createCanvas() function creates the canvas that we will draw to - you will most likely see this function at the top of every P5 program/sketch. Takes as input the width and height parameters for the dimensions of the canvas.
It creates an HTML canvas element and attaches it to the DOM.
Here's a simple example:
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(2)
}
function draw() {
background(220);
for(let n = 0; n < 150; n++){
fill(random(255), random(255), random(255))
ellipse(random(windowWidth), random(windowHeight), random(10, 50))
}
}
In creative coding, sketches are like mini, experimental programs. They're not full-fledged projects, but act as quick explorations to test ideas, learn new coding tricks, and rapidly build prototypes. This lets creative coders play, discover, and iterate without worrying about a perfect final product.
On the canvas, the coordinate system is flipped vertically. The origin is basically in the top left corner in this manner:
You can make custom shapes with the beginShape(), vertex(), and endShape() functions:
You can also draw shapes with your own custom stroke style and colors:
P5JS provides an internal transformation matrix that allows you to manipulate the position and orientation of the drawn shapes. Essentially alter the coordinate system:
Idea: place circles on the canvas in such a manner that they don't overlap -> creates an interesting pattern.
Anything that's unclear? Needs additional information?
How can we best package this for the students. How do you usually go about preparing material?
A first look at animation