What's p5.js?
...
For the purpose of the course we are going to use Openprocessing.org. It's an online platform, where anyone can create and share visual-based, open source projects. The big advantage of open processing is that the users can like and comment other sketches, follow other users and create themed collections.
...
In order to understand the examples and to write your own programs, you will be using references, i.e. artifacts that describe a programming language.
Basic Sketch
Every p5.js programm consists of setup() and draw() function. Setup() runs when the program starts and it is used to set the initial environment properties. Draw() executes the code inside the block until the program is stopped or noLoop() is called.
Code Block | ||||
---|---|---|---|---|
| ||||
function setup() { // setup stuff } function draw() { // draw stuff } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
function setup(){ createCanvas(300,300); // define window size stroke(255,255,255); // define line colour } } function draw() { background(0); // define background colour line(100,10,100,150); // draw a line line(150,10,150,200); line(200,10,200,250); fill(0,0,0); // define fill colour strokeWeight(5); // line thickness ellipse(100,150,50,50); // draw an ellipse ellipse(150,200,50,50); // draw an ellipse noFill(); // turn of fill ellipse(200,250,50,50); // draw an ellipse } |
...