FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
moe
moep5
Remix of saolsen/p5
Public
Like
1
p5
Home
Code
2
README.md
main.tsx
Branches
1
Pull requests
Remixes
1
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
Sign up now
Code
/
Code
/
Search
README.md

P5 sketch

Easily turn a p5.js sketch into a val. See https://www.val.town/v/saolsen/p5_sketch for an example.

Usage

  • Make a p5 sketch, you can import the p5 types to make it easier.
import type * as p5 from "npm:@types/p5";
  • Export any "global" p5 functions. These are functions like setup and draw that p5 will call.

  • Set the val type to http and default export the result of sketch, passing in import.meta.url.

A full example looks like this.

import type * as p5 from "npm:@types/p5"; export function setup() { createCanvas(400, 400); } export function draw() { if (mouseIsPressed) { fill(0); } else { fill(255); } ellipse(mouseX, mouseY, 80, 80); } import { sketch } from "https://esm.town/v/saolsen/p5"; export default sketch(import.meta.url);

How it works

The sketch function returns an http handler that sets up a basic page with p5.js added. It then imports your module from the browser and wires up all the exports so p5.js can see them. All the code in your val will run in the browser (except for the default sketch export) so you can't call any Deno functions, environment variables, or other server side apis.

Migrated from folder: art/p5

Code
README.mdmain.tsx
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.