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.

Predefined variables in p5.js

Predefined variables in p5.js

- [Instructor] P5.js, being a super helpful library, has a couple of predefined variables that we can use to obtain certain values. Two such variable names that we can use are width and height. By using these variable names inside the setup and draw functions, we can get the current camera size. This would allow us to do the same thing that we have been trying to do by defining our own variable names. P5.js developers must have realized this is something that a lot of developers will try to do by themselves. Enhance providers, an easier solution to the problem, given that this code actually can be written like this. So, instead of having these variables here, I can again define, or hardcore, these values into my create canvas function. But here, instead of referring to canvas width and canvas height, I can simply type widths and heights, that's our p5.js providers variable names, that would give me the current canvas size.…

Contents