[p5.js] What is p5.js

Get Started

This page walks you through setting up a p5.js project and making your first sketch. If you'd like to start with the new p5.js Web Editor, you can jump down to Your First Sketch.

Download and File Setup


The easiest way to start is by using the empty example that comes with thep5.js complete download.
If you look in index.html, you'll notice that it links to the file p5.js. If you would like to use the minified version (compressed for faster page loading), change the link to p5.min.js.
A sample HTML page might look like this:
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.js"></script>
    <script src="sketch.js"></script>
  </head>
  <body>
  </body>
</html>
You can also start with this template from codepen.

Your First Sketch


Processing users may want to check out the Processing transition tutorial.
In your editor, type the following:
function setup() {

}

function draw() {
  ellipse(50, 50, 80, 80);
}
This line of code means "draw an ellipse, with the center 50 pixels over from the left and 50 pixels down from the top, with a width and height of 80 pixels".
Save your sketch and refresh your page view in your browser. If you've typed everything correctly, you'll see this appear in the display window:

Comments

Popular posts from this blog

[OpenCV] What is gocv?

[OpenCV] Chapter01-05 Working with UI elements such as scrollbars in OpenCV window

[OpenCV] How to set up gocv