Simple p5 sketch
In order to include a P5.js sketch in your post:
- make sure that you are importing the p5.js library as a dependency. You can complete the front-matter of the post like this:
- create in
div
in the markdown document of your post and include the javascript file (relative path from the markdown document). Note that we gave thediv
a custom id.
- in your javascript file, make sure to link the canvas to this specific
div
. See the documentation for more information.
Note: using the method, you can only include a single sketch per file. See here if you want to have several sketches running simultaneously.
Handling dependencies:
In this example we are only loading the p5.js
library. However you might want to use
other librairies later. In order to add a library, expand the file _data/dependencies.yml
:
Each entry in this file is composed of a name
and an element
- The
name
is an alias that you can use in the list of dependencies defined in the front-matter of the article. - The
element
is a script tag linking to a library hosted by a content-delivery-network cdnjs for example.