All Projects → dnass → Svelte Canvas

dnass / Svelte Canvas

🎨 Reactive canvas rendering with Svelte.

Projects that are alternatives of or similar to Svelte Canvas

Svelte Custom Elements
Turn Svelte components into web components
Stars: ✭ 45 (-23.73%)
Mutual labels:  svelte
Vue Luck Draw
🎖🎖🎖 一个基于 vue2 / vue3 的【大转盘 / 九宫格】抽奖插件;🎉 A lucky draw plug-in based on vue2 / vue3;🎨 奖品 / 文字 / 图片 / 颜色 / 按钮均可配置,支持同步 / 异步抽奖,🎯 概率前 / 后端可控,自动根据 dpr 调整清晰度适配移动端
Stars: ✭ 1,056 (+1689.83%)
Mutual labels:  canvas
Svelte Simple Datatables
A Datatable component for Svelte
Stars: ✭ 56 (-5.08%)
Mutual labels:  svelte
Smileyrating
SmileyRating is a simple rating bar for android. It displays animated smileys as rating icon.
Stars: ✭ 1,038 (+1659.32%)
Mutual labels:  canvas
Literallycanvas
A canvas in your browser. Literally.
Stars: ✭ 1,043 (+1667.8%)
Mutual labels:  canvas
Gobang html5
五子棋,gobang,html5,canvas,js游戏,普通ai算法
Stars: ✭ 53 (-10.17%)
Mutual labels:  canvas
Drawing Board
在线画板,基于 Canvas 和 JavaScript 的画图工具。
Stars: ✭ 44 (-25.42%)
Mutual labels:  canvas
Svelte Starter
A Svelte starter template for projects.
Stars: ✭ 57 (-3.39%)
Mutual labels:  svelte
Mopaint
🎨💪 Modern, modular paint and more! (pre-alpha, not much done yet)
Stars: ✭ 50 (-15.25%)
Mutual labels:  canvas
Deep Viz
A React component library, providing concise and beautiful diversity charts with Canvas, SVG, E-map, WebGL, Dom, based on data visualization experience and commercial data display practice.
Stars: ✭ 55 (-6.78%)
Mutual labels:  canvas
Curtainsjs
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.
Stars: ✭ 1,039 (+1661.02%)
Mutual labels:  canvas
Svelte Typescript Parcel
Svelte + Typescript + Parcel
Stars: ✭ 48 (-18.64%)
Mutual labels:  svelte
Svelte Store Router
Store-based router for Svelte
Stars: ✭ 54 (-8.47%)
Mutual labels:  svelte
Interference2020
Interference2020 Website
Stars: ✭ 46 (-22.03%)
Mutual labels:  svelte
Svelte Input Mask
Input masking component for Svelte with simple API and rich customization
Stars: ✭ 56 (-5.08%)
Mutual labels:  svelte
Gomoku
this is a Gomoku game's client and server, which bulid by canvas and swoole
Stars: ✭ 44 (-25.42%)
Mutual labels:  canvas
Glslcanvas
Simple tool to load GLSL shaders on HTML Canvas using WebGL
Stars: ✭ 1,067 (+1708.47%)
Mutual labels:  canvas
Calendar Graph
Calendar graph like github using jsx support SVG, Canvas and SSR
Stars: ✭ 58 (-1.69%)
Mutual labels:  canvas
React Handy Renderer
✏️ Draw 2D primitives in sketchy style with React
Stars: ✭ 56 (-5.08%)
Mutual labels:  canvas
Android Toy
不积跬步 无以至千里
Stars: ✭ 54 (-8.47%)
Mutual labels:  canvas

svelte-canvas

Reactive canvas rendering with Svelte.

Installation

npm install svelte svelte-canvas

Usage

<script>
  import { Canvas, Layer, t } from "svelte-canvas";

  $: render = ({ context, width, height }) => {
    context.fillStyle = `hsl(${$t / 40}, 100%, 50%)`;
    context.beginPath();
    context.arc(($t / 4) % width, ($t / 4) % height, 100, 0, Math.PI * 2);
    context.fill();
  };
</script>

<Canvas width={640} height={640}>
  <Layer {render} />
</Canvas>

More examples:

API

Canvas

Canvas is the top-level element. It's a Svelte wrapper around an HTML <canvas> element.

Parameters

parameter default description
width 640 Canvas width
height 640 Canvas height
pixelRatio window.devicePixelRatio Canvas pixel ratio
style null A CSS style string which will be applied to the canvas element
autoclear true If true, will use context.clearRect to clear the canvas at the start of each render cycle

Methods

method description
getCanvas Returns a reference to the canvas DOM element
getContext Returns the canvas's 2D rendering context
redraw Forces a re-render of the canvas

Events

All DOM events on the <canvas> element are forwarded to the Canvas component, so handling an event is as simple as <Canvas on:click={handleClick}>.

Layer

Layer is a layer to be rendered onto the canvas. It takes three props: setup, render, and priority. setup and render both require functions with one argument, that receives an object with the properties context, width, and height. context is the 2D rendering context of the parent canvas. width and height are the canvas's dimensions.

setup is optional and is called once at initialization. render is called every time the canvas redraws.

Declaring your render function reactively lets svelte-canvas re-render anytime the values that the function depends on change.

The third prop, priority, takes a positive integer which determines the layer's render priority. Layers with a priority will be rendered after other layers, in ascending order of priority, so that higher priority layers appear on top of the scene.

t

t is a readable store that provides the time in milliseconds since initialization. Subscribing to t within your render function lets you easily create animations.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].