User:Neoksaal/Tutorials/p5js
Element
preload() setup() draw()
A function that's called once to load assets before the sketch runs.
Declaring the functionpreload()sets a code block to run once automatically beforesetup()ordraw(). It's used to load assets including multimedia files, fonts, data, and 3D models:
- ↳ 외부리소스를 쓸때 적절
A function that's called once when the sketch begins running.
Declaring the functionsetup()sets a code block to run once automatically when the sketch starts running. It's used to perform setup tasks such as creating the canvas and initializing variables
Code placed insetup()will run once before code placed indraw()begins looping. If thepreload()is declared, thensetup()will run immediately afterpreload()finishes loading assets.
A function that's called repeatedly while the sketch runs.
Declaring the functiondraw()sets a code block to run repeatedly once the sketch starts. It’s used to create animations and respond to user inputs.
This is often called the "draw loop" because p5.js calls the code indraw()in a loop behind the scenes. By default,draw()tries to run 60 times per second. The actual rate depends on many factors. The drawing rate, called the "frame rate", can be controlled by callingframeRate(). The number of times draw() has run is stored in the system variableframeCount().
Code placed withindraw()begins looping aftersetup()runs.draw()will run until the user closes the sketch.draw()can be stopped by calling thenoLoop()function.draw()can be resumed by calling theloop()function.
create