Skip to main content

Arrays

Difficulty : Beginner-Intermediate This tutorial assumes you have a basic understanding of coding in Processing or p5, and are comfortable using variables, if statements and for loops.

So far we've learnt that we can use variables to name data in our code, as so:

var myVariable = 200;

console.log(myVariable);

https://editor.p5js.org/odmundeetgen/sketches/Kdvb2jJ3z

And we know that we can use these variable in our sketch. In the following example I create variables X and Y, and use them to as the x and y coordinates in an ellipse function

var x = 100; var y = 100;

function setup() { createCanvas(400, 400); }

function draw() { background(220);

ellipse(x, y, 20,20); } arraysTutorial_IMG001.png

Now what if we wanted to have a lot of circles, like in the image below?

arraysTutorial_IMG002.png