generate-random-shapes v0.0.2
Overview
This is a simple library for generating quasi-random shapes in the plane of specified complexity and smoothnes.
The shape boundary is represented as a loop (an array) of cubic bezier curves.
Credits
Installation
npm install generate-random-shapes
This package is ESM only.
It can be used in Node.js
or in a browser.
Usage
In addition to generateRandomShape
the following convenience functions are also exported:
pointsToShape
pointsToSimplePolygon
setShapeSmoothness
moveShapeCentroidToOrigin
setShapeSize
setShapeRotation
Node.js
import { generateRandomShape } from 'generate-random-shapes';
const shape = generateRandomShape(0, 5, 1);
console.log(shape); //=> [[[-0.2372092174828731, -0.6962315314077125], [-0.444758140717...
// ...
Browsers - directly, without a bundler, using the pre-bundled minified .js file
<!doctype html>
<html lang="en">
<head>
<script type="module">
import { generateRandomShape } from './node_modules/generate-random-shapes/browser/index.min.js';
const shape = generateRandomShape(0, 5, 1);
console.log(shape); //=> [[[-0.2372092174828731, -0.6962315314077125], [-0.444758140717...
// ...
</script>
</head>
<body>Check the console.</body>
</html>
Bundlers (Webpack, Rollup, ...)
Webpack will be taken as an example here.
Since your webpack config file might still use CommonJS
you must rename
webpack.config.js
to webpack.config.cjs
.
If you are using TypeScript:
Since this is an ESM only
library you must use resolve-typescript-plugin
in your webpack.config.cjs
file.
npm install --save-dev resolve-typescript-plugin
and follow the instructions given at resolve-typescript-plugin.
Additionally, follow this guide.
License
Public Domain and/or WTFPL v. 4.0
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENCE Version 4.0, July 2019
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENCE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION
- You just DO WHAT THE FUCK YOU WANT TO.