1.1.4 • Published 1 year ago

useless-blobs v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Useless Blobs

Parametrized random SVG blob creation. Playground here

Installation

npm install useless-blobs

Generate SVG Path String

There are various helpers that are exported in case you want finer control.

import generateBlobPath, { createPolygon, generatePathString } from 'useless-blobs';

const options = { 
    verts: 6, 
    width: 200, 
    height: 200, 
    irregularity: .25, 
    spikiness: .5, 
    boundingShape: 'ellipsis'
};
const smoothing = 1;

// will only generate an array of points
const polygonPoints = createPolygon(options);

// creates an svg path from an array of points and a smoothing value between them
const pathString = generatePathString(polygonPoints, smoothing);

// a helper that wraps the previous two functions into one
const otherPathString = generateBlobPath({...options, smoothing});

// no options are required
const defaultPathString = generateBlobPath();

The resulting path string from generateBlobPath or generatePathString can then be used within the d value of a <path> tag in an SVG as outline here.

Options

OptionDescriptionAllowed ValuesOptionalDefault
vertsNumber of vertices shape will containAny integer >= 36
widthWidth in pixels of resulting shapeAny integer > 0200
heightHeight in pixels or resulting shapeAny integer > 0200
irregularityAffects deviation between angles of each point0,1.25
spikinessAffect how much a point deviates from the bounding shape0,1.5
boundingShapeDefines shape points will be limited withinrectangle or ellipsisellipsis
smoothingAffects how jagged final curve will be0,11

React Component

There is also a React component exported to simplify use for React projects.

import UselessBlob from 'useless-blobs/lib/components';

<UselessBlob />

// or

<UselessBlob
    fill='red'
    stroke='blue'
    verts={12}
    height={200}
    width={500}
    irregularity={0.5}
    spikiness={0.8}
    boundingShape='rectangle'
/>

It should be noted that for the React component all props follow the same name and requirements as the options table with additional props for:

OptionDescriptionAllowed ValuesOptionalDefault
fillWhat color to paint blobAny color'black'
strokeColor of stroke around blobAny color'transparent'
styleIn-line style object to apply to underlying <svg> tagReact in-line style objectundefined
pathStyleIn-line style object to apply to underlying <path> tagReact in-line style object{ transition: '.25s' }
classNameCSS class to apply to underlying <svg> tagStringundefined
1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago