Skip to main content

Week 4 - Other inputs and APIs


  • Independently researching new features of p5.js using the documentation
  • Using inputs to control behaviour of your sketch
  • Understanding the concept of web-based APIs and basic use
  • In groups create a sketch that uses either at least one input (learnt today) or APIs to create an interactive sketch

Local web server

So far during this series of workshops testing your code has involved opening the index.html file in your browser, which results in an absolute file path in the browser address bar (see below). You can see this indicated by the file:// protocol followed by the absolute file path to the index.html file:

For some examples you will need to run a local HTTP web server that serves the files in a project. If you have Node.js already installed you can run the following command to install an HTTP web server:

sudo npm install -g http-server

If you receive an error from the above command it's likely that you do not have Node.js installed. In which case visit the Node.js homepage and download/install the LTS version and repeat the command above.

Once you have installed the HTTP web server you will need to change directory (cd) into the project directory on the command line and run the server:

cd ~/Desktop/intro-to-programming-2017/15_image_pixel_array/

If successful you will see messages in the command line similar to this:

You can then copy and paste one of the URLs into you browser:

Other Inputs

So far you have used the input for mouse position to affect the visual output in your sketch.

There are a range of other inputs we can use to create dynamic / interactive sketches:

  • Click
  • Keyboard
  • Touch / Drag
  • Rotation

Experiment with these other inputs using the p5.js reference. Search for ‘Events’ section in the reference.


Supporting Code
The code to support this section is located in the following directory and is available to view on Github:

Here are a list of APIs you can use for this example: