2.0.0 • Published 5 years ago

metaballs-js v2.0.0

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

metaballs-js

NPM License BundlePhobia Last Commit

Demo

Playground / Demo

Features

  • Create animated metaballs in all numbers, colors, sizes, velocities.
  • Light-weight: Written in plain WebGL without any other dependencies. BundlePhobia
  • Performant: Makes use of GPU hardware acceleration. The performance solely depends on the number of metaballs.

Install

npm install --save metaballs-js

Usage

import initMetaballs from "metaballs-js";

const options = {
  numMetaballs: 100,
  minRadius: 3,
  maxRadius: 7.5,
  speed: 10.0,
  color: '#ff0024',
  backgroundColor: '#121212',
  useDevicePixelRatio: true
}

const cssSelector = '#canvasId'
initMetaballs(cssSelector, options)

// in your HTML
<html>
  <body>
    <canvas id="canvasId"></canvas>
  </body>
</html>

Options

NameDescriptionTypeDefault Value
numMetaballsThe number of metaballs to displayNumber100
minRadiusminimum radius of a metaballNumber3
maxRadiusmaximum radius of a metaballNumber7.5
speedmaximum speed of a metaballNumber10.0
colorcolor of the metaballsString#ff0024 '#ff0024'
backgroundColorThe background color of the canvasString#121212 '#121212'
interactiveCreate a metaball at cursor position listening to mouse move events. Valid values are window or canvasString or Booleanfalse
useDevicePixelRatioUse more pixels matching the device pixel ratioBooleantrue

Limitations

Metaballs-js currently uses uniforms to send the metaball positions to the GPU / shaders. There are specific device restrictions on the max number of uniforms, i.e., also on the max number of metaballs one can render at a time. If this happens you will see the following error thrown:

Shader compile failed with: ERROR: too many uniforms

This is especially problematic on mobile phones.

Resources

License

MIT © MrToph

2.0.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago