# shape

Simple 2D shape generators

``npm install shape``

# shape

A simple set of geometric shape generators, starting with the simple stuff.

## Reference

### poly

``````poly(n, l, clamp?)
``````

Create a polygon starting and ending at [0, 0] with `n` sides of length `l`. Allows partial application (i.e. if `l` is not supplied a function accepting `l` and generating the poly will be returned).

Like other functions in the shape toolbox, clamping defaults to true.

``````var poly = require('shape/poly');

// generate a square
console.log(poly(4, 100));
// --> [ [ 0, 0 ], [ 0, 100 ], [ 100, 100 ], [ 100, 0 ], [ 0, 0 ] ]

// generate a triangle
console.log(poly(3, 100));
// --> [ [ 0, 0 ], [ 0, 100 ], [ 86, 50 ], [ 0, 0 ] ]

// generate a triangle with no clamping
console.log(poly(3, 100, false));
// --> [ [ 0, 0 ], [ 0, 100 ], [ 86.60254037844388, 50.00000000000002 ], [ 4.263256414560601e-14, -2.1316282072803006e-14 ] ]
``````

### square

``````square(size, clamp?)
``````

For those times you don't want to type poly(4) we do it for you.

``````var square = require('shape/square');

// generate a square
console.log(square(100));
// --> [ [ 0, 0 ], [ 0, 100 ], [ 100, 100 ], [ 100, 0 ], [ 0, 0 ] ]

// generate an unclamped square
console.log(square(25.5, false));
// --> [ [ 0, 0 ], [ 0, 25.5 ], [ 25.5, 25.5 ], [ 25.500000000000004, 0 ], [ 3.552713678800501e-15, -4.684119303370593e-15 ] ]
``````