0.1.0 • Published 7 years ago

cycle-canvas-points v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

cycle-canvas-points

build npm

A Cycle.js driver for writing imageData values to canvas elements.

API

canvasPointsDriver

The expected sink$ is a stream of objects with the following members:

  • canvas: HTMLCanvasElement – A <canvas> element (likely selected from sources.DOM)
  • draw: (x: number, y: number) => number[] – A function that accepts x and y numbers as coordinates, and returns an array of three numbers that correspond to RGB color values (0–255).

Example

import canvasPointsDriver from 'cycle-canvas-points'
import { h } from '@cycle/dom'
import { run } from '@cycle/xstream-run'

function main (sources) {
  const testDraw$ = sources.select('canvas.test').elements()
    .map(canvas => ({ canvas, draw: (x, y) => [x, y, 0] }))

  const vdom$ = h('div', [
    h('canvas.test', { attrs: { height: 128, width: 256 } })
  ])

  return {
    DOM: vdom$,
    testCanvas: testDraw$
  }
}

run(main, {
  DOM: document.body,
  testCanvas: canvasPointsDriver
})
0.1.0

7 years ago

0.1.0-pre.1

7 years ago