p5.js
Introductory p5.js notes
Updated: 03 September 2023
Notes from
p5.js
and The Nature of Code
Random Walk
Using p5
we can create a random walker. With p5
we usually structure stuff using OOP, for example we will define a random walker with the ability to take a new step as well as render itself:
Walker.js
We also need to create a walker instance and define the needed setup
and draw
functions for p5
:
sketch.js
Random Coloured Walkers
We can also create a whole bunch of random walkers with random colours like so:
Vectors
p5
also contains a Vector Class, this is a class of functions that allows us to work with vectors as mathematical structures
We can create a bouncing ball animation by using two vectors, one for position
and one for velocity
we can apply some vector math to get the ball to bounce around the screen
We cal also do something like the above using a 3D canvas