0.1.7 • Published 9 months ago

svelte-physics-renderer v0.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

svelte-physics-renderer

A simple HTML-based physics renderer for Svelte, using MatterJS under the hood.

Example Usage

<script lang="ts">
  let canvas = $state<Canvas>();

  let id = 0;
  let mounted = false;

	$effect(() => {
		if (!mounted) {
			canvas!.context.start();
			mounted = true;
		}
	});

  $effect(() => {
    return () => {
      canvas!.context.stop();
    }
  });
</script>

<Canvas
  width='600px'
  height='400px'
  gravity={{ scale: 0.0005 }}
  interactive
  bind:this={canvas}
>
  <Circle
    size={64}
    friction={0.001}
    restitution={0.8}
    randomBackground>
    <!-- put any HTML you want here! -->
    <span>Hello world!</span>
  </Circle>
  <Rectangle
    style="width: 192px; height: 64px;"
    friction={0.001}
    restitution={0.8}
    randomBackground>
    <!-- put any HTML you want here! -->
    <span>I'm a rectangle!</span>
  </Rectangle>
</Canvas>
0.1.7

9 months ago

0.1.6

9 months ago

0.1.5

10 months ago

0.1.4

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago