Code Monkey home page Code Monkey logo

what-is-p5's Introduction

Objectives

  1. Introduce the JavaScript library p5
  2. Create a basic p5 sketch

What is p5

p5 is a library, or collection of code, that makes it easier to quickly create visual experiences in the browser. It accomplishes this by abstracting certain technologies and interfaces that can be cumbersome to work with as a burgeoning programmer. Most notably, p5 makes it quick and easy to work with the HTML <canvas> element. <canvas> works just as it is named: to use it you describe precisely which lines and shapes should be drawn within the element.

Incorporating the p5 Library

Luckily for us, p5 is freely available and we could download it directly. For use in our websites, we will incorporate a <script> tag that will automatically pull the whole library from the internet! This is convenient because it:

  • Reduces the burden on us, as programmers, to store and serve the library to clients
  • Ensures we are using the current version of p5

This script tag will be all we need to make sure p5 is loaded:

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.js"></script>

Using p5

Let's get started and have some fun with p5! In this directory, you will find two source files: index.html and myFirstSketch.js. Both of the files have a couple TODOs in them. Take a look and, if possible, work with a partner in solving them.

  • Run the application with npm run start and inspect the program in the browser
  • Make sure both p5 as well as myFirstSketch are being loaded by index.html with <script> tags
  • Follow the prompts in myFirstSketch.js to get started in creating a basic p5 sketch
  • If refreshing your browser does not seem to be updating correctly after you change your JavaScript code, you may need to clear your browser cache. In chrome, try two-finger clicking the refresh button

After the TODOs have been completed your program should behave similar the gif below:

what-is-p5's People

Contributors

danielseehausen avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.