A template for showcasing animated p5.js sketches. Built with sveltekit.
Add your own sketches with the included template. Customize controls to add interactivity. Showcase your brand with configurable social links. Publish easily with the included infra files.
- Mobile Friendly
- Light Mode / Dark Mode detection
- Sketches Pause & Resume automatically
- Use this template on GitHub or clone the repo
- Install dependencies:
npm install
- Start the dev server:
npm run dev
src/lib/components/sketches/
├── SketchCard.svelte # Reusable wrapper with automatic visibility tracking
├── types.ts # Shared TypeScript types
├── _template/ # Template for creating new sketches
│ ├── template.svelte # Component template
│ └── script.svelte.ts # p5.js sketch logic template
├── mosaic-morph/ # Example sketch
│ ├── mosaic-morph.svelte
│ └── script.svelte.ts
└── your-new-sketch/ # Add new sketches here!
├── your-sketch.svelte
└── script.svelte.ts
-
Copy the template folder:
cp -r src/lib/components/sketches/_template src/lib/components/sketches/your-sketch-name
-
Rename the component file:
mv src/lib/components/sketches/your-sketch-name/template.svelte \ src/lib/components/sketches/your-sketch-name/your-sketch-name.svelte
-
Edit
script.svelte.ts:- Add your sketch-specific configuration to
SketchConfig - Implement your
setup()anddraw()functions - The pause/resume functionality is already built in!
- Add your sketch-specific configuration to
-
Edit the
.sveltecomponent:- Update the title in
<SketchCard title="your-sketch-name"> - Add any controls your sketch needs in the
{#snippet controls()}block - Pass configuration values to
createSketch() - Add any sketch-specific props (e.g.,
initialSpeed,initialSize)
- Update the title in
-
Add to the carousel in
+page.svelte:<script> import MosaicMorph from "$lib/components/sketches/mosaic-morph/mosaic-morph.svelte"; import YourSketch from "$lib/components/sketches/your-sketch-name/your-sketch-name.svelte"; </script> <Carousel.Root> <Carousel.Content> <Carousel.Item> <MosaicMorph initialSize={0.4} initialSpeed={0.8} /> </Carousel.Item> <Carousel.Item> <YourSketch /> </Carousel.Item> </Carousel.Content> </Carousel.Root>
The carousel automatically tracks which sketch is visible—no manual index prop required!
Carousel.Itemassigns each item a unique index via Svelte contextSketchCardretrieves this index and compares it to the carousel'sselectedIndex- When
selectedIndex === itemIndex, the sketch is marked asisActive - The sketch component uses a
$effectto callpause()orresume()on the p5 controller - The p5 sketch uses
noLoop()andloop()to pause/resume the draw loop
This ensures only the currently visible sketch is running its animation loop, saving CPU/GPU resources.
Edit src/lib/components/socials.svelte to add your own branding and social links. The template includes ready-to-use icon snippets for Discord, LinkedIn, SoundCloud, and more.
| Command | Description |
|---|---|
npm run dev |
Start development server |
npm run build |
Build for production |
npm run preview |
Preview production build |
Want to share publically? Your gallery is ready to roll with the include docker-compose stack. See infra/README.md for detailed instructions.
MIT
