## Functions
CSG
clone the given object
Converts an CSS color name to RGB color.
CSG
apply the given color to the input object(s)
Converts an RGB color value to HSL. Conversion formula adapted from http://en.wikipedia.org/wiki/HSL_color_space. Assumes r, g, and b are contained in the set [0, 1] and returns h, s, and l in the set [0, 1].
Converts an HSL color value to RGB. Conversion formula adapted from http://en.wikipedia.org/wiki/HSL_color_space. Assumes h, s, and l are contained in the set [0, 1] and returns r, g, and b in the set [0, 1].
Converts an RGB color value to HSV. Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space. Assumes r, g, and b are contained in the set [0, 1] and returns h, s, and v in the set [0, 1].
Converts an HSV color value to RGB. Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space. Assumes h, s, and v are contained in the set [0, 1] and returns r, g, and b in the set [0, 1].
Converts a HTML5 color value (string) to RGB values See the color input type of HTML5 forms Conversion formula:
Converts RGB color value to HTML5 color value (string) Conversion forumla:
CSG
union/ combine the given shapes
CSG
difference/ subtraction of the given shapes ie: cut out C From B From A ie : a - b - c etc
CSG
intersection of the given shapes: ie keep only the common parts between the given shapes
CSG
linear extrusion of the input 2d shape
CSG
rotate extrusion / revolve of the given 2d shape
CSG
rectangular extrusion of the given array of points
CSG
translate an object in 2D/3D space
CSG
scale an object in 2D/3D space
CSG
rotate an object in 2D/3D space
CSG
apply the given matrix transform to the given objects
CSG
center an object in 2D/3D space
CSG
mirror an object in 2D/3D space
CSG/CAG
expand an object in 2D/3D space
CSG/CAG
contract an object(s) in 2D/3D space
CSG
create a minkowski sum of the given shapes
CSG
create a convex hull of the given shapes
CSG
create a chain hull of the given shapes Originally "Whosa whatsis" suggested "Chain Hull" , as described at https://plus.google.com/u/0/105535247347788377245/posts/aZGXKFX1ACN essentially hull A+B, B+C, C+D and then union those
CAG
Construct a square/rectangle
CAG
Construct a circle
CAG
Construct a polygon either from arrays of paths and points, or just arrays of points nested paths (multiple paths) and flat paths are supported
CAG
Construct a triangle
CSG
Construct a cuboid
CSG
Construct a sphere
CSG
Construct a cylinder
CSG
Construct a torus
CSG
Construct a polyhedron from the given triangles/ polygons/points
Object
Construct a with, segments tupple from a character
Array
Construct an array of with, segments tupple from a string
CSG
clone the given object
**Kind**: global function
**Returns**: CSG
- new CSG object , a copy of the input
| Param | Type | Description |
| --- | --- | --- |
| obj | Object
| the object to clone by |
**Example**
```js
let copy = clone(sphere())
```
## css2rgb(String) ⇒
Converts an CSS color name to RGB color.
**Kind**: global function
**Returns**: Array The RGB representation, or [0,0,0] default
| Param | Description |
| --- | --- |
| String | s The CSS color name |
## color(color, objects) ⇒ CSG
apply the given color to the input object(s)
**Kind**: global function
**Returns**: CSG
- new CSG object , with the given color
| Param | Type | Description |
| --- | --- | --- |
| color | Object
| either an array or a hex string of color values |
| objects | Object
\| Array
| either a single or multiple CSG/CAG objects to color |
**Example**
```js
let redSphere = color([1,0,0,1], sphere())
```
## rgb2hsl(Number, Number, Number) ⇒
Converts an RGB color value to HSL. Conversion formula
adapted from http://en.wikipedia.org/wiki/HSL_color_space.
Assumes r, g, and b are contained in the set [0, 1] and
returns h, s, and l in the set [0, 1].
**Kind**: global function
**Returns**: Array The HSL representation
| Param | Description |
| --- | --- |
| Number | r The red color value |
| Number | g The green color value |
| Number | b The blue color value |
## hsl2rgb(Number, Number, Number) ⇒
Converts an HSL color value to RGB. Conversion formula
adapted from http://en.wikipedia.org/wiki/HSL_color_space.
Assumes h, s, and l are contained in the set [0, 1] and
returns r, g, and b in the set [0, 1].
**Kind**: global function
**Returns**: Array The RGB representation
| Param | Description |
| --- | --- |
| Number | h The hue |
| Number | s The saturation |
| Number | l The lightness |
## rgb2hsv(Number, Number, Number) ⇒
Converts an RGB color value to HSV. Conversion formula
adapted from http://en.wikipedia.org/wiki/HSV_color_space.
Assumes r, g, and b are contained in the set [0, 1] and
returns h, s, and v in the set [0, 1].
**Kind**: global function
**Returns**: Array The HSV representation
| Param | Description |
| --- | --- |
| Number | r The red color value |
| Number | g The green color value |
| Number | b The blue color value |
## hsv2rgb(Number, Number, Number) ⇒
Converts an HSV color value to RGB. Conversion formula
adapted from http://en.wikipedia.org/wiki/HSV_color_space.
Assumes h, s, and v are contained in the set [0, 1] and
returns r, g, and b in the set [0, 1].
**Kind**: global function
**Returns**: Array The RGB representation
| Param | Description |
| --- | --- |
| Number | h The hue |
| Number | s The saturation |
| Number | v The value |
## html2rgb()
Converts a HTML5 color value (string) to RGB values
See the color input type of HTML5 forms
Conversion formula:
- split the string; "#RRGGBB" into RGB components
- convert the HEX value into RGB values
**Kind**: global function
## rgb2html()
Converts RGB color value to HTML5 color value (string)
Conversion forumla:
- convert R, G, B into HEX strings
- return HTML formatted string "#RRGGBB"
**Kind**: global function
## union(objects) ⇒ CSG
union/ combine the given shapes
**Kind**: global function
**Returns**: CSG
- new CSG object, the union of all input shapes
| Param | Type | Description |
| --- | --- | --- |
| objects | Object(s)
\| Array
| objects to combine : can be given - one by one: union(a,b,c) or - as an array: union([a,b,c]) |
**Example**
```js
let unionOfSpherAndCube = union(sphere(), cube())
```
## difference(objects) ⇒ CSG
difference/ subtraction of the given shapes ie:
cut out C From B From A ie : a - b - c etc
**Kind**: global function
**Returns**: CSG
- new CSG object, the difference of all input shapes
| Param | Type | Description |
| --- | --- | --- |
| objects | Object(s)
\| Array
| objects to subtract can be given - one by one: difference(a,b,c) or - as an array: difference([a,b,c]) |
**Example**
```js
let differenceOfSpherAndCube = difference(sphere(), cube())
```
## intersection(objects) ⇒ CSG
intersection of the given shapes: ie keep only the common parts between the given shapes
**Kind**: global function
**Returns**: CSG
- new CSG object, the intersection of all input shapes
| Param | Type | Description |
| --- | --- | --- |
| objects | Object(s)
\| Array
| objects to intersect can be given - one by one: intersection(a,b,c) or - as an array: intersection([a,b,c]) |
**Example**
```js
let intersectionOfSpherAndCube = intersection(sphere(), cube())
```
## linear_extrude([options], baseShape) ⇒ CSG
linear extrusion of the input 2d shape
**Kind**: global function
**Returns**: CSG
- new extruded shape
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | Object
| | options for construction |
| [options.height] | Float
| 1
| height of the extruded shape |
| [options.slices] | Integer
| 10
| number of intermediary steps/slices |
| [options.twist] | Integer
| 0
| angle (in degrees to twist the extusion by) |
| [options.center] | Boolean
| false
| whether to center extrusion or not |
| baseShape | CAG
| | input 2d shape |
**Example**
```js
let revolved = linear_extrude({height: 10}, square())
```
## rotate_extrude([options], baseShape) ⇒ CSG
rotate extrusion / revolve of the given 2d shape
**Kind**: global function
**Returns**: CSG
- new extruded shape
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | Object
| | options for construction |
| [options.fn] | Integer
| 1
| resolution/number of segments of the extrusion |
| [options.startAngle] | Float
| 1
| start angle of the extrusion, in degrees |
| [options.angle] | Float
| 1
| angle of the extrusion, in degrees |
| [options.overflow] | Float
| 'cap'
| what to do with points outside of bounds (+ / - x) : defaults to capping those points to 0 (only supported behaviour for now) |
| baseShape | CAG
| | input 2d shape |
**Example**
```js
let revolved = rotate_extrude({fn: 10}, square())
```
## rectangular_extrude(basePoints, [options]) ⇒ CSG
rectangular extrusion of the given array of points
**Kind**: global function
**Returns**: CSG
- new extruded shape
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| basePoints | Array
| | array of points (nested) to extrude from layed out like [ [0,0], [10,0], [5,10], [0,10] ] |
| [options] | Object
| | options for construction |
| [options.h] | Float
| 1
| height of the extruded shape |
| [options.w] | Float
| 10
| width of the extruded shape |
| [options.fn] | Integer
| 1
| resolution/number of segments of the extrusion |
| [options.closed] | Boolean
| false
| whether to close the input path for the extrusion or not |
| [options.round] | Boolean
| true
| whether to round the extrusion or not |
**Example**
```js
let revolved = rectangular_extrude({height: 10}, square())
```
## translate(vector, ...objects) ⇒ CSG
translate an object in 2D/3D space
**Kind**: global function
**Returns**: CSG
- new CSG object , translated by the given amount
| Param | Type | Description |
| --- | --- | --- |
| vector | Object
| 3D vector to translate the given object(s) by |
| ...objects | Object(s)
\| Array
| either a single or multiple CSG/CAG objects to translate |
**Example**
```js
let movedSphere = translate([10,2,0], sphere())
```
## scale(scale, ...objects) ⇒ CSG
scale an object in 2D/3D space
**Kind**: global function
**Returns**: CSG
- new CSG object , scaled by the given amount
| Param | Type | Description |
| --- | --- | --- |
| scale | Float
\| Array
| either an array or simple number to scale object(s) by |
| ...objects | Object(s)
\| Array
| either a single or multiple CSG/CAG objects to scale |
**Example**
```js
let scaledSphere = scale([0.2,15,1], sphere())
```
## rotate(rotation, objects) ⇒ CSG
rotate an object in 2D/3D space
**Kind**: global function
**Returns**: CSG
- new CSG object , rotated by the given amount
| Param | Type | Description |
| --- | --- | --- |
| rotation | Float
\| Array
| either an array or simple number to rotate object(s) by |
| objects | Object(s)
\| Array
| either a single or multiple CSG/CAG objects to rotate |
**Example**
```js
let rotatedSphere = rotate([0.2,15,1], sphere())
```
## transform(matrix, ...objects) ⇒ CSG
apply the given matrix transform to the given objects
**Kind**: global function
**Returns**: CSG
- new CSG object , transformed
| Param | Type | Description |
| --- | --- | --- |
| matrix | Array
| the 4x4 matrix to apply, as a simple 1d array of 16 elements |
| ...objects | Object(s)
\| Array
| either a single or multiple CSG/CAG objects to transform |
**Example**
```js
const angle = 45
let transformedShape = transform([
cos(angle), -sin(angle), 0, 10,
sin(angle), cos(angle), 0, 20,
0 , 0, 1, 30,
0, 0, 0, 1
], sphere())
```
## center(axis, ...objects) ⇒ CSG
center an object in 2D/3D space
**Kind**: global function
**Returns**: CSG
- new CSG object , translated by the given amount
| Param | Type | Description |
| --- | --- | --- |
| axis | Boolean
\| Array
| either an array or single boolean to indicate which axis you want to center on |
| ...objects | Object(s)
\| Array
| either a single or multiple CSG/CAG objects to translate |
**Example**
```js
let movedSphere = center(false, sphere())
```
## mirror(vector, ...objects) ⇒ CSG
mirror an object in 2D/3D space
**Kind**: global function
**Returns**: CSG
- new CSG object , mirrored
| Param | Type | Description |
| --- | --- | --- |
| vector | Array
| the axes to mirror the object(s) by |
| ...objects | Object(s)
\| Array
| either a single or multiple CSG/CAG objects to mirror |
**Example**
```js
let rotatedSphere = mirror([0.2,15,1], sphere())
```
## expand(radius, object) ⇒ CSG/CAG
expand an object in 2D/3D space
**Kind**: global function
**Returns**: CSG/CAG
- new CSG/CAG object , expanded
| Param | Type | Description |
| --- | --- | --- |
| radius | float
| the radius to expand by |
| object | Object
| a CSG/CAG objects to expand |
**Example**
```js
let expanededShape = expand([0.2,15,1], sphere())
```
## contract(radius, object) ⇒ CSG/CAG
contract an object(s) in 2D/3D space
**Kind**: global function
**Returns**: CSG/CAG
- new CSG/CAG object , contracted
| Param | Type | Description |
| --- | --- | --- |
| radius | float
| the radius to contract by |
| object | Object
| a CSG/CAG objects to contract |
**Example**
```js
let contractedShape = contract([0.2,15,1], sphere())
```
## minkowski(objects) ⇒ CSG
create a minkowski sum of the given shapes
**Kind**: global function
**Returns**: CSG
- new CSG object , mirrored
| Param | Type | Description |
| --- | --- | --- |
| objects | Object(s)
\| Array
| either a single or multiple CSG/CAG objects to create a hull around |
**Example**
```js
let hulled = hull(rect(), circle())
```
## hull(objects) ⇒ CSG
create a convex hull of the given shapes
**Kind**: global function
**Returns**: CSG
- new CSG object , a hull around the given shapes
| Param | Type | Description |
| --- | --- | --- |
| objects | Object(s)
\| Array
| either a single or multiple CSG/CAG objects to create a hull around |
**Example**
```js
let hulled = hull(rect(), circle())
```
## chain_hull(objects) ⇒ CSG
create a chain hull of the given shapes
Originally "Whosa whatsis" suggested "Chain Hull" ,
as described at https://plus.google.com/u/0/105535247347788377245/posts/aZGXKFX1ACN
essentially hull A+B, B+C, C+D and then union those
**Kind**: global function
**Returns**: CSG
- new CSG object ,which a chain hull of the inputs
| Param | Type | Description |
| --- | --- | --- |
| objects | Object(s)
\| Array
| either a single or multiple CSG/CAG objects to create a chain hull around |
**Example**
```js
let hulled = chain_hull(rect(), circle())
```
## square([options]) ⇒ CAG
Construct a square/rectangle
**Kind**: global function
**Returns**: CAG
- new square
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | Object
| | options for construction |
| [options.size] | Float
| 1
| size of the square, either as array or scalar |
| [options.center] | Boolean
| true
| wether to center the square/rectangle or not |
**Example**
```js
let square1 = square({
size: 10
})
```
## circle([options]) ⇒ CAG
Construct a circle
**Kind**: global function
**Returns**: CAG
- new circle
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | Object
| | options for construction |
| [options.r] | Float
| 1
| radius of the circle |
| [options.fn] | Integer
| 32
| segments of circle (ie quality/ resolution) |
| [options.center] | Boolean
| true
| wether to center the circle or not |
**Example**
```js
let circle1 = circle({
r: 10
})
```
## polygon([options]) ⇒ CAG
Construct a polygon either from arrays of paths and points, or just arrays of points
nested paths (multiple paths) and flat paths are supported
**Kind**: global function
**Returns**: CAG
- new polygon
| Param | Type | Description |
| --- | --- | --- |
| [options] | Object
| options for construction |
| [options.paths] | Array
| paths of the polygon : either flat or nested array |
| [options.points] | Array
| points of the polygon : either flat or nested array |
**Example**
```js
let poly = polygon([0,1,2,3,4])
or
let poly = polygon({path: [0,1,2,3,4]})
or
let poly = polygon({path: [0,1,2,3,4], points: [2,1,3]})
```
## triangle() ⇒ CAG
Construct a triangle
**Kind**: global function
**Returns**: CAG
- new triangle
**Example**
```js
let triangle = trangle({
length: 10
})
```
## cube([options]) ⇒ CSG
Construct a cuboid
**Kind**: global function
**Returns**: CSG
- new sphere
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | Object
| | options for construction |
| [options.size] | Float
| 1
| size of the side of the cuboid : can be either: - a scalar : ie a single float, in which case all dimensions will be the same - or an array: to specify different dimensions along x/y/z |
| [options.fn] | Integer
| 32
| segments of the sphere (ie quality/resolution) |
| [options.fno] | Integer
| 32
| segments of extrusion (ie quality) |
| [options.type] | String
| 'normal'
| type of sphere : either 'normal' or 'geodesic' |
**Example**
```js
let cube1 = cube({
r: 10,
fn: 20
})
```
## sphere([options]) ⇒ CSG
Construct a sphere
**Kind**: global function
**Returns**: CSG
- new sphere
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | Object
| | options for construction |
| [options.r] | Float
| 1
| radius of the sphere |
| [options.fn] | Integer
| 32
| segments of the sphere (ie quality/resolution) |
| [options.fno] | Integer
| 32
| segments of extrusion (ie quality) |
| [options.type] | String
| 'normal'
| type of sphere : either 'normal' or 'geodesic' |
**Example**
```js
let sphere1 = sphere({
r: 10,
fn: 20
})
```
## cylinder([options]) ⇒ CSG
Construct a cylinder
**Kind**: global function
**Returns**: CSG
- new cylinder
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | Object
| | options for construction |
| [options.r] | Float
| 1
| radius of the cylinder |
| [options.r1] | Float
| 1
| radius of the top of the cylinder |
| [options.r2] | Float
| 1
| radius of the bottom of the cylinder |
| [options.d] | Float
| 1
| diameter of the cylinder |
| [options.d1] | Float
| 1
| diameter of the top of the cylinder |
| [options.d2] | Float
| 1
| diameter of the bottom of the cylinder |
| [options.fn] | Integer
| 32
| number of sides of the cylinder (ie quality/resolution) |
**Example**
```js
let cylinder = cylinder({
d: 10,
fn: 20
})
```
## torus([options]) ⇒ CSG
Construct a torus
**Kind**: global function
**Returns**: CSG
- new torus
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | Object
| | options for construction |
| [options.ri] | Float
| 1
| radius of base circle |
| [options.ro] | Float
| 4
| radius offset |
| [options.fni] | Integer
| 16
| segments of base circle (ie quality) |
| [options.fno] | Integer
| 32
| segments of extrusion (ie quality) |
| [options.roti] | Integer
| 0
| rotation angle of base circle |
**Example**
```js
let torus1 = torus({
ri: 10
})
```
## polyhedron([options]) ⇒ CSG
Construct a polyhedron from the given triangles/ polygons/points
**Kind**: global function
**Returns**: CSG
- new polyhedron
| Param | Type | Description |
| --- | --- | --- |
| [options] | Object
| options for construction |
| [options.triangles] | Array
| triangles to build the polyhedron from |
| [options.polygons] | Array
| polygons to build the polyhedron from |
| [options.points] | Array
| points to build the polyhedron from |
| [options.colors] | Array
| colors to apply to the polyhedron |
**Example**
```js
let torus1 = polyhedron({
points: [...]
})
```
## vector_char(x, y, char) ⇒ Object
Construct a with, segments tupple from a character
**Kind**: global function
**Returns**: Object
- { width: X, segments: [...] }
| Param | Type | Description |
| --- | --- | --- |
| x | Float
| x offset |
| y | Float
| y offset |
| char | Float
| character |
**Example**
```js
let charData = vector_char(0, 12.2, 'b')
```
## vector_text(x, y, string) ⇒ Array
Construct an array of with, segments tupple from a string
**Kind**: global function
**Returns**: Array
- [{ width: X, segments: [...] }]
| Param | Type | Description |
| --- | --- | --- |
| x | Float
| x offset |
| y | Float
| y offset |
| string | Float
| string |
**Example**
```js
let stringData = vector_text(0, 12.2, 'b')
```