- clone(obj) ⇒
CSG
clone the given object
- css2rgb(String) ⇒
Converts an CSS color name to RGB color.
- color(color, objects) ⇒
CSG
apply the given color to the input object(s)
- 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].
- 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].
- 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].
- 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].
- 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
- rgb2html()
Converts RGB color value to HTML5 color value (string) Conversion forumla:
- convert R, G, B into HEX strings
- return HTML formatted string "#RRGGBB"
- union(objects) ⇒
CSG
union/ combine the given shapes
- difference(objects) ⇒
CSG
difference/ subtraction of the given shapes ie: cut out C From B From A ie : a - b - c etc
- intersection(objects) ⇒
CSG
intersection of the given shapes: ie keep only the common parts between the given shapes
- linear_extrude([options], baseShape) ⇒
CSG
linear extrusion of the input 2d shape
- rotate_extrude([options], baseShape) ⇒
CSG
rotate extrusion / revolve of the given 2d shape
- rectangular_extrude(basePoints, [options]) ⇒
CSG
rectangular extrusion of the given array of points
- translate(vector, ...objects) ⇒
CSG
translate an object in 2D/3D space
- scale(scale, ...objects) ⇒
CSG
scale an object in 2D/3D space
- rotate(rotation, objects) ⇒
CSG
rotate an object in 2D/3D space
- transform(matrix, ...objects) ⇒
CSG
apply the given matrix transform to the given objects
- center(axis, ...objects) ⇒
CSG
center an object in 2D/3D space
- mirror(vector, ...objects) ⇒
CSG
mirror an object in 2D/3D space
- expand(radius, object) ⇒
CSG/CAG
expand an object in 2D/3D space
- contract(radius, object) ⇒
CSG/CAG
contract an object(s) in 2D/3D space
- minkowski(objects) ⇒
CSG
create a minkowski sum of the given shapes
- hull(objects) ⇒
CSG
create a convex hull of the given shapes
- 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
- square([options]) ⇒
CAG
Construct a square/rectangle
- circle([options]) ⇒
CAG
Construct a circle
- 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
- triangle() ⇒
CAG
Construct a triangle
- cube([options]) ⇒
CSG
Construct a cuboid
- sphere([options]) ⇒
CSG
Construct a sphere
- cylinder([options]) ⇒
CSG
Construct a cylinder
- torus([options]) ⇒
CSG
Construct a torus
- polyhedron([options]) ⇒
CSG
Construct a polyhedron from the given triangles/ polygons/points
- vector_char(x, y, char) ⇒
Object
Construct a with, segments tupple from a character
- vector_text(x, y, string) ⇒
Array
Construct an array of with, segments tupple from a string
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
let copy = clone(sphere())
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 |
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
let redSphere = color([1,0,0,1], sphere())
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 |
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 |
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 |
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 |
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
Converts RGB color value to HTML5 color value (string) Conversion forumla:
- convert R, G, B into HEX strings
- return HTML formatted string "#RRGGBB"
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
let unionOfSpherAndCube = union(sphere(), cube())
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
let differenceOfSpherAndCube = difference(sphere(), cube())
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
let intersectionOfSpherAndCube = intersection(sphere(), cube())
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
let revolved = linear_extrude({height: 10}, square())
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
let revolved = rotate_extrude({fn: 10}, square())
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
let revolved = rectangular_extrude({height: 10}, square())
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
let movedSphere = translate([10,2,0], sphere())
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
let scaledSphere = scale([0.2,15,1], sphere())
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
let rotatedSphere = rotate([0.2,15,1], sphere())
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
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 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
let movedSphere = center(false, sphere())
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
let rotatedSphere = mirror([0.2,15,1], sphere())
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
let expanededShape = expand([0.2,15,1], sphere())
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
let contractedShape = contract([0.2,15,1], sphere())
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
let hulled = hull(rect(), circle())
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
let hulled = hull(rect(), circle())
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
let hulled = chain_hull(rect(), circle())
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
let square1 = square({
size: 10
})
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
let circle1 = circle({
r: 10
})
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
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]})
Construct a triangle
Kind: global function
Returns: CAG
- new triangle
Example
let triangle = trangle({
length: 10
})
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
let cube1 = cube({
r: 10,
fn: 20
})
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
let sphere1 = sphere({
r: 10,
fn: 20
})
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
let cylinder = cylinder({
d: 10,
fn: 20
})
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
let torus1 = torus({
ri: 10
})
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
let torus1 = polyhedron({
points: [...]
})
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
let charData = vector_char(0, 12.2, 'b')
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
let stringData = vector_text(0, 12.2, 'b')