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.
npm install
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:
SketchConfigsetup() and draw() functionsEdit the .svelte component:
<SketchCard title="your-sketch-name">{#snippet controls()} blockcreateSketch()initialSpeed, initialSize)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.Item assigns each item a unique index via Svelte contextSketchCard retrieves this index and compares it to the carousel's selectedIndexselectedIndex === itemIndex, the sketch is marked as isActive$effect to call pause() or resume() on the p5 controllernoLoop() and loop() to pause/resume the draw loopThis 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