Particle Logo

Add a particle logo animation to Svelte & SvelteKit

Because Particle Logo exports plain 2D Canvas math and raw point-cloud JSON, you can drop the animation into SvelteKit without adding Three.js or heavy wrappers.

Updated

1. Keep Canvas logic inside onMount

SvelteKit runs component scripts during SSR where window and HTMLCanvasElement do not exist. Initialize your 2D context and requestAnimationFrame loop inside onMount and cancel the frame on cleanup:

<script lang="ts">
  import { onMount } from 'svelte';

  let container: HTMLDivElement;
  let canvas: HTMLCanvasElement;
  // Paste rawPoints from Particle Logo (or JSON export)
  const rawPoints: [number, number, string?][] = [];

  onMount(() => {
    const ctx = canvas.getContext('2d');
    if (!ctx) return;
    let raf = 0;
    const render = () => {
      // Draw particle frame on canvas
      raf = requestAnimationFrame(render);
    };
    raf = requestAnimationFrame(render);
    return () => cancelAnimationFrame(raf);
  });
</script>

<div bind:this={container} class="particle-wrap">
  <canvas bind:this={canvas}></canvas>
</div>

2. Two clean ways to ship

Open the workbench

More guides