Using Constructor Objects in p5.js
Introduction
p5.js allows us to use Javascript features such as Objects. An Object in p5.js is a form of data + a set of things you can do with that data, what are called methods. Think of an Object as a spanner in your toolkit, which can tell you the gauge/size of mechanical components and also do specific things with these.
When would we need to use these?
Some libraries in p5.js, such as p5.sound create Oscillator objects, which can generate sounds with different frequencies. And these have methods associated with them, such as turning them on/off, modifying their amplitudes and frequencies (“modulations”).
We can also create our own Objects which can include some methods of their own.
Examples of Objects
Let us see an example of a built-in Object type offered by p5.js. Then we will look at the way in which we can create Objects of our own.
Objects in the p5.sound library
Creating our own Obects
References
- Dan Shiffman, of course: