Demo: https://svelte.dev/repl/93a34e18da1d44b29283eb0d1e293eb5?version=3.19.2
This is a proof-of-concept showing how to integrate flexible UI components for a p5.js sketch. This uses Svelte.
A framework that allows us to write simple p5.js sketches with:
- An easy way to add in GUI sliders, color pickers, etc
- Possibility to build your own UI sliders/tooling on a per-project basis
- Reactivity builtin, so that binding UI to variables is easy
- The possibility of more advanced features in a bespoke tool
See the two files below:
- SimpleSketch.svelte — just a simple example showing a UI binding
- ComplexSketch.svelte — a more advanced example decoupling one UI change from another
The next step is to try and wrap this within a tool/UI interface so that it isn't confined to the Svelte REPL.
This is testing some ideas and musings on ways to improve creative coding tools within JavaScript. The goal is to maintain a low barrier to entry while supporting more flexible and advanced use cases.
For example, the above could be simplified and made into a more purpose-built tool:
// a helper to allow p5 functions/variables as if in global mode
@with(p5)
// a helper that binds the variable to a new color picker UI
@Color()
export let color = 'red';
@Slider({ min: 0, max: 1, step: 0.01 })
export let radius = 0.5;
export function draw () {
background(color);
circle(width / 2, height / 2, radius * min(width, height));
}