Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const hexagon = []
for (let i = 0; i < 12; i++) { // -- shell like
const x = sin(i / 12 * 180) * 10
const y = cos(i / 12 * 180) * 10
shell.push(
translate([x, y, 0], scale(6 - i / 2, circle())) // { center: true }
)
}
const n = 6
for (let i = 0; i < n; i++) { // -- hexagon chain hulled
const x = sin(i / n * 360) * 10
const y = cos(i / n * 360) * 10
hexagon.push(
translate([x, y, 0], circle())// { center: true }
)
}
return [
translate([-20, 0, 0],
extrudeLinear({ height: 5 }, hullChain(shell))
),
hullChain(shell),
translate([20, 0, 0],
union(shell)
),
translate([-25, 40, 0],
extrudeLinear({ height: 5 }, hullChain({ closed: true }, hexagon))
),
translate([0, 40, 0],
shell.push(
translate([x, y, 0], scale(6 - i / 2, circle())) // { center: true }
)
}
const n = 6
for (let i = 0; i < n; i++) { // -- hexagon chain hulled
const x = sin(i / n * 360) * 10
const y = cos(i / n * 360) * 10
hexagon.push(
translate([x, y, 0], circle())// { center: true }
)
}
return [
translate([-20, 0, 0],
extrudeLinear({ height: 5 }, hullChain(shell))
),
hullChain(shell),
translate([20, 0, 0],
union(shell)
),
translate([-25, 40, 0],
extrudeLinear({ height: 5 }, hullChain({ closed: true }, hexagon))
),
translate([0, 40, 0],
hullChain({ closed: true }, hexagon)
),
translate([25, 40, 0],
union(hexagon)
)
const main = () => {
const testCube = cube()
return [
translate([0, 10, 0], testCube), // simple translation
translate([10, 0, 0], rotate([10, 5, 0], testCube)), // translate + rotate
translate([-10, 0, 0], scale([0.5, 0.5, 5], testCube)), // translate + scale
transform([ // matrix transform
cos(15), -sin(15), 0, 0,
sin(15), cos(15), 0, 0,
0, 0, 1, 1,
0, 0, 0, 1
], testCube)
]
}
const path2Example = color('black',
path2.fromPoints({ }, points) // it also works with ccw points ie points.reverse()
)
const expandedPath2 = expand({ delta: 2, corners: 'round', segments: 8 }, path2Example)
// but also 2d geometry
const geom2Example = geom2.fromPoints([[-8, -8], [8, -8], [8, 8], [-8, 8]])
const expandedGeom2 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom2 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
// aaand 3d geometry
const geom3Example = color('black',
cuboid()
)
const expandedGeom3 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom3 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
return [
path2Example,
expandedPath2,
//
geom2Example,
expandedGeom2,
contractedGeom2,
const geom2Example = geom2.fromPoints([[-8, -8], [8, -8], [8, 8], [-8, 8]])
const expandedGeom2 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom2 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
// aaand 3d geometry
const geom3Example = color('black',
cuboid()
)
const expandedGeom3 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom3 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
return [
path2Example,
expandedPath2,
//
geom2Example,
expandedGeom2,
contractedGeom2,
//
geom3Example,
expandedGeom3,
contractedGeom3
]
const main = () => {
// you can expand 2d paths
const points = [
[10, 0],
[9.510565162951535, 3.090169943749474],
[8.090169943749475, 5.877852522924732],
[5.877852522924732, 8.090169943749475],
[3.0901699437494745, 9.510565162951535],
[6.123233995736766e-16, 10]
]
const path2Example = color('black',
path2.fromPoints({ }, points) // it also works with ccw points ie points.reverse()
)
const expandedPath2 = expand({ delta: 2, corners: 'round', segments: 8 }, path2Example)
// but also 2d geometry
const geom2Example = geom2.fromPoints([[-8, -8], [8, -8], [8, 8], [-8, 8]])
const expandedGeom2 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom2 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
// aaand 3d geometry
const geom3Example = color('black',
cuboid()
[8.090169943749475, 5.877852522924732],
[5.877852522924732, 8.090169943749475],
[3.0901699437494745, 9.510565162951535],
[6.123233995736766e-16, 10]
]
const path2Example = color('black',
path2.fromPoints({ }, points) // it also works with ccw points ie points.reverse()
)
const expandedPath2 = expand({ delta: 2, corners: 'round', segments: 8 }, path2Example)
// but also 2d geometry
const geom2Example = geom2.fromPoints([[-8, -8], [8, -8], [8, 8], [-8, 8]])
const expandedGeom2 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom2 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
// aaand 3d geometry
const geom3Example = color('black',
cuboid()
)
const expandedGeom3 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom3 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
return [
path2Example,
const points = [
[10, 0],
[9.510565162951535, 3.090169943749474],
[8.090169943749475, 5.877852522924732],
[5.877852522924732, 8.090169943749475],
[3.0901699437494745, 9.510565162951535],
[6.123233995736766e-16, 10]
]
const path2Example = color('black',
path2.fromPoints({ }, points) // it also works with ccw points ie points.reverse()
)
const expandedPath2 = expand({ delta: 2, corners: 'round', segments: 8 }, path2Example)
// but also 2d geometry
const geom2Example = geom2.fromPoints([[-8, -8], [8, -8], [8, 8], [-8, 8]])
const expandedGeom2 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom2 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
// aaand 3d geometry
const geom3Example = color('black',
cuboid()
)
const expandedGeom3 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom3 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
const expandedPath2 = expand({ delta: 2, corners: 'round', segments: 8 }, path2Example)
// but also 2d geometry
const geom2Example = geom2.fromPoints([[-8, -8], [8, -8], [8, 8], [-8, 8]])
const expandedGeom2 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom2 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
// aaand 3d geometry
const geom3Example = color('black',
cuboid()
)
const expandedGeom3 = color('red',
expand({ delta: 2, corners: 'round', segments: 8 }, geom2Example)
)
const contractedGeom3 = color('red',
expand({ delta: -2, corners: 'round', segments: 8 }, geom2Example)
)
return [
path2Example,
expandedPath2,
//
geom2Example,
expandedGeom2,
contractedGeom2,
//
geom3Example,
expandedGeom3,
/* title : Chain Hull
// author : Rene K. Mueller, Moissette Mark
// license : MIT License
// date : 2013/04/18
// description: Whosa whatsis suggested "Chain Hull" as described at
// https://plus.google.com/u/0/105535247347788377245/posts/aZGXKFX1ACN
*/
const { sin, cos } = Math
const { circle } = require('@jscad/modeling').primitives
const { translate, scale } = require('@jscad/modeling').transforms
const { union } = require('@jscad/modeling').booleans
const { hullChain } = require('@jscad/modeling').hulls
const { extrudeLinear } = require('@jscad/modeling').extrusions
const main = () => {
const shell = []
const hexagon = []
for (let i = 0; i < 12; i++) { // -- shell like
const x = sin(i / 12 * 180) * 10
const y = cos(i / 12 * 180) * 10
shell.push(
translate([x, y, 0], scale(6 - i / 2, circle())) // { center: true }
)
}