p5.js JavaScript creative-coding library for interactive graphics and browser-based sketches.
Overview p5.js is a free JavaScript library for creative coding, including interactive graphics and animation on a web page. It can be used through an online editor or as a library in a locally developed web project. Its sketch-oriented model offers an alternative to desktop creative-coding environments when browser delivery is part of the requirement.[1] [2] [3]
Contents Writing and delivering a sketch A p5.js sketch is JavaScript source used in a web page. The online editor provides a direct authoring route, while the local-development tutorial describes editing project files and viewing them through a development server in a browser. The library is distinct from the editor: downloading its complete distribution does not include an installed editing application.[2] [6]
Canvas and rendering choices createCanvas establishes the sketch's drawing surface, with P2D or WebGL rendering options. WebGL2 is used when supported by the browser, with a WebGL1 option also documented. WebGPU requires its own mode add-on and asynchronous canvas creation. These are environment-dependent rendering paths, so the presence of a drawing API does not establish identical graphics behavior across every browser and device.[3]
Describing visual output The describe function attaches an author-supplied explanation to the canvas for screen readers. It can also display that text beside the canvas as a visible label. This provides a practical accessibility mechanism for visual sketches, but its usefulness depends on the description written for the actual work; the function does not automatically infer the meaning of a generated image or interaction.[4]
Migrating to version 2 The version-2 teaching guide identifies input events and asset loading as common migration points. Mouse-button handling becomes an object with individual button states, and the guide moves loading from preload into asynchronous setup with await. Optional Data & Events and Preload compatibility add-ons can retain older patterns. The guide is deliberately scoped to common educational code, rather than a claim that these are the only changes affecting every existing application.[5]
Pinning the library and sound support The download page offers a pinned 2.3.3 library URL separately from a floating latest-version URL. Sound is maintained in p5.sound rather than the main library. It warns that a sound file included in a complete download may be outdated and incompatible with p5.js 2.x. Reproducing a working audiovisual sketch therefore requires recording the sound dependency as well as the core version.[6]
Licensing boundaries The p5.js library is licensed under LGPL 2.1. The website has a different license, and its reference and example pages use CC BY-NC-SA 4.0. Those distinctions matter when distributing library code, adapting documentation examples or supplying original artwork: the library's availability does not put every adjacent asset under the same terms. This article is original research prose rather than a copied example sketch.[7]
Substitution considerations p5.js can substitute for Processing for interactive visual experiments where browser access is preferable to distributing a desktop Java application. The shared sketch concept provides a useful conceptual bridge, but it does not establish source compatibility. Java-specific libraries, filesystem assumptions and renderer behavior need separate replacements or revisions. The assessment is based on documented development models; no port, installation or performance comparison was executed.[2] [3] [8]
Also included: 3 capabilities and 0 substitute relationships. Check substitutes in section 1 and capabilities in section 3.