Skip to content

A simple template for using P5.js with Typescript, built using Vite

Notifications You must be signed in to change notification settings

WilliamIPark/pretty-p5-ts-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pretty P5 TypeScript Template

Motivation

I quite often want to create things using p5.js, and so far I've usually created them over on my codepen, which is a great place to write small sketches with p5. I recommend setting up a project there if you're doing something small too. There isn't a great place to get started with larger projects though.

If you want something that is going to be a little more than a sketch, and you want to split your code up to keep it maintainable, this might be for you. It is the environment I would want to work in for any P5 project larger than a sketch.

P5 _ Typescript

Installation

  • Pull this repo down.
  • Run npm install to download the dependancies.
  • Run npm run dev to load up the webpage.

Benifits of this template

  • Uses Vite for its environment which:
    • Provides TypeScript support out of the box.
    • Allows you to split up your code into modules.
    • Provides fast reload, so your browser will refresh with each change.
  • Provides optional, but useful defaults for things like:
    • Code organisation
    • Easy importing with aliasing
  • Uses P5.js in instance mode, allowing you to create many instances of P5.
  • I've tried to make the page with your canvas minimal but cosy.

Get started

  • The root typescript file is src/main.ts, this is where you will find the template's default P5 instance being created and mounted to the page.
  • By default (and completely optional), the P5 life cycle methods are split into their own files: src/lifecycle/setup.ts & src/lifecycle/draw.ts.
  • Utility functions can be created and accessed easily in src/utils, and one is provided as an example.
  • If you care to modify the page's styles, look in src/style.css

Aliases

Aliases are a way to have easy access to certain files in your directory, when doing an import. 4 Aliases are set up by default:

  • @ points to src/
  • @lifecycles points to src/lifecycles
  • @utils points to src/utils
  • @types points to src/types

Examples of usage can be found in the code, but as a reference an import from one of this directories would look like:

import { lerpWithSin } from "@utils/lerp-with-sin";

About

A simple template for using P5.js with Typescript, built using Vite

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published