0.0.8 • Published 7 years ago

jelly.js v0.0.8

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

Jelly.js

A library to draw and animate "jelly" shapes in a canvas element. It's inspired in this pen by Thom Chiovoloni, inspired as well in the game The Floor is Jelly.

DEMO 1 - Simple example

DEMO 2 - Jelly slider

TUTORIAL 1 - Simple example

TUTORIAL 2 - Jelly slider

Install

You can install it using npm or just downloading it manually.

NPM

npm install jelly.js

Basic usage

1. Include jelly.js or jelly.min.js somewhere in HTML.

<script src="js/jelly.js"></script>

2. Add the SVG paths you'd like to draw, and a canvas to draw them.

<!-- Circle path -->
<svg class="jelly-circle-svg" width="1000" height="600" style="display: none">
    <path d="m500 250c27.614 0 50 22.386 50 50s-22.386 50-50 50-50-22.386-50-50 22.386-50 50-50z"/>
    <!-- You can have multiple paths -->
</svg>

<!-- Canvas to draw the shape -->
<!-- Note that the `svg` and `canvas` elements have the same dimensions -->
<canvas class="jelly-circle-canvas" width="1000" height="600"></canvas>

3. Initialize it in JavaScript.

// The `Jelly` constructor receive a `canvas` element (or `string` selector) and an array of objects as `options` (see details below).
// You need to pass as many options as shapes you want to draw in the `canvas`
// This time we are providing an array with a single element, as we want to draw a single shape
var myJellyCircle = new Jelly('.jelly-circle-canvas', [{paths: '.jelly-circle-svg path'}]);

Options

Here is the complete list of options you can provide to customize the jelly shapes as needed:

NameTypeDefaultDescription
pathsElement or StringundefinedPath elements (or selector) to draw the shapes. This options is required.
svgStringundefinedURL to an .svg file containing the paths. You can also insert the SVG code directly in the HTML.
pointsNumberInteger10Number of points to use to draw the shapes.
maxDistanceFloat70Max distance (in pixels) among points to start pulling.
mouseIncidenceFloat40Incidence of the mouse. More incidence means more reaction, and it increases proportionately to mouse speed.
maxIncidenceFloat40Max incidence of the mouse. No matter the speed, incidence will never be greater than this value.
colorString'#666'Solid color to fill the shape.
borderStringundefinedSolid color to draw a border around the shape.
borderWidthInt4Width for border around the shape.
imageStringundefinedImage URL to fill the shape.
imageCentroidBooleantrueIf true, the image will be moved accordingly to the centroid point.
centroidElement or StringundefinedElement (or selector) to move accordingly to the centroid point.
debugBooleanfalseSet it true to see the points.
intensityFloat0.95Jelly effect intensity. Should be a value < 1.
fastnessFloat1 / 40Jelly effect fastness. Should be a value near zero.

Available functions to animate the jelly shapes

NameDefault optionsDescription
hide{i: 0, maxDelay: 0, animate: true}Hide the shape selected by the index (i). If animate is true, all the points of the shape will be animated, with a random delay <= maxDelay.
show{i: 0, maxDelay: 0, animate: true}Show the shape selected by the index (i). If animate is true, all the points of the shape will be animated, with a random delay <= maxDelay. To show a shape, it should have been hidden previously.
morph{i: 0, maxDelay: 0, animate: true}Morph the shape selected by the index (i) to another shape. You need to pass a new paths option (at least) with the same pointsNumber. If animate is true, all the points of the shape will be animated, with a random delay <= maxDelay.
shake{i: 0, x: 0, y: 0}Shake the shape selected by the index (i), moving the points (alternately) the distance defined by x and y.
0.0.8

7 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago