From the course: Coding for Visual Learners: Learning JavaScript from Scratch

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Getting started with p5.js

Getting started with p5.js

- [Instructor] If you are using an online code editor, you can just refresh your page to be able to get a clean slate to begin coding with JavaScript and p5.js. What we see when we open up the p5.js online code editor are two function declarations with the name setup and draw. These two function declarations need to be made for pretty much every p5.js program that we would write. P5.js finds these function definitions in our code and executes whatever is inside them for us but there's a difference in how these functions are executed. The block inside the setup function, the area in between the curly brackets is the place where we will be writing the code that is to be executed for the initialization of our program. Code written inside the setup function is executed only once before the draw function. The draw function is where the real magic happens. Any code that is written inside the draw function is repeatedly…

Contents