Skip to content

dylanpyle/vf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vf

[v]isual e[f]fects / [v]ector [f]ields / [v]ery [f]un

Demo

https://vector.demo.camp

Usage

(Though we do host a copy, you can too - hotlink at your own risk)

<script src='https://vector.demo.camp/lib.js'></script>

<script>
  new VFCanvas({
    el: canvas,
    xEquation: "mX - x",
    yEquation: "(mY - y) + Math.cos((2*t - 1) * Math.PI)",

    backgroundColor: '#fff',
    foregroundColor: '#000',

    type: 'DOT',
    clamp: true,
    spacing: 40
  });
</script>

Supports the following required options:

  • el — a HTMLCanvasElement
  • xEquation — An equation for the X component of each vector
    • e.g. vx=Math.pow(x,2)-mX
    • Should generally return values in the 0-1 range.
  • yEquation — An equation for the Y component of each vector
    • e.g. vx=Math.pow(Y,2)-mY
    • Should generally return values in the 0-1 range.
  • backgroundColor — The background color (e.g. #000 or magenta)
  • foregroundColor — The foreground color
  • type — The type of stroke to draw (ARROW or LINE)
    • See the demo above for different examples
  • clamp — Whether or not to restrict equation outputs to values of 0-1.
  • spacing — The spacing betweeen each arrow, in pixels
    • Can be any number, but it's best to stay above ~30px to achieve adequate performnace.

Writing Equations

Equations are evaluated as JavaScript (i.e. use Math functions as needed) 1 with access to the following variables:

  • x, y - The arrow's logical position (-1 to 1)
  • mX, mY - The current logical position of the cursor (-1 to 1)
  • t - A unit of time, which grows from 0-1 every 10 seconds

Examples

Local Development

Prerequisites

Usage

./x dev

License

MIT

Footnotes

Footnotes

  1. No built-in XSS protections are in place, so careful when passing user input, or clicking unfamiliar links on the demo domain.

About

A vector field toolkit for the browser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published