The following list contains all of the p5.js functions and variables used in this guide, as well as links to their respective reference pages in the p5.js library documentation.
These are the two key functions that you should define yourself in your Javascript code whenever you use the p5.js library:
setup()
is where you'd create the canvas and do any initialization tasks. It runs once when the program first starts on page load.draw()
is where you can incorporate interactivity and animation into your program. It loops continuously as long as the program is running.createCanvas()
creates a new canvas element of the specified width and height.windowWidth
and windowHeight
are the width and height of the browser window in pixels.background()
sets the background color of the canvas.mouseX
and mouseY
are the the X and Y coordinates of the mouse's current location.pmouseX
and pmouseY
are the the X and Y coordinates of the mouse's previous location.mouseIsPressed
is a boolean variable that is true
if the mouse button is currently pressed or false
if not.frameCount
is an integer that contains how many frames have passed so far, or in other words, the total number of calls to draw()
so far.stroke()
sets the stroke color.strokeWeight()
sets the width of the stroke, or line thickness, in pixels.
noStroke()
disables drawing the stroke.fill()
sets the fill color.
noFill()
disables filling in shapes with color.