0.2.22 • Published 2 years ago

permutable v0.2.22

Weekly downloads
161
License
-
Repository
github
Last release
2 years ago

Permutable

Tools for programming graphics

Usage

The recommended way is using ECMAScript modules (esm):

<script type='module'>
  import { mix, run } from 'https://unpkg.com/permutable@{{VERSION}}?module'
</script>

Examples

API

run

Run a single program

run(program)

mix

Mix multiple programs

mix([
  program1,
  program2
])

program

A program is defined as a plain JavaScript object

{
  name: string,
  params: object,
  setup: function
}

Example:

{
  name: 'circle',
  params: {
    stroke: {
      type: 'toggle',
      value: true
    }
  },
  setup: function (canvas) {
    const context = canvas.getContext('2d')

    return function render ({ stroke }) {
      if (stroke) {
        context.strokeRect(0, 0, 100, 100)
      } else {
        context.fillRect(0, 0, 100, 100)
      }
    }
  }
}

name (string)

A name for the program

params (object)

Parameters for the program. These are the types available:

number
{
  type: 'number',
  value: 5,
  min: 0,
  max: 10,
  step: 1
}
timer
{
  type: 'timer'
}
toggle
{
  type: 'toggle',
  value: false
}
trigger
{
  type: 'trigger'
}
bpm
{
  type: 'bpm'
  value: 120,
  step: 1
}

setup (function)

A setup function will run once when the program is loaded. In it, the canvas element is being provided as a parameter. A render function is expected to be returned from the setup function. It will be called anytime the params changes.

Example with 2d context:

function setup (canvas) {
  const context = canvas.getContext('2d')

  return function render (values) {
    context.strokeRect(0, 0, 100, 100)
  }
}

Example using regl:

function setup (canvas) {
  const regl = createREGL({ canvas })

  return function render (values) {
    regl.poll()
    regl.clear({
      color: [1, 0, 0, 1]
    })
  }
}
0.2.22

2 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.17

4 years ago

0.2.16

4 years ago

0.2.15

5 years ago

0.2.14

5 years ago

0.2.13

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago