How to use @jscad/modeling - 10 common examples

To help you get started, we’ve selected a few @jscad/modeling examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jscad / OpenJSCAD.org / packages / examples / core / hulls / hullChain.js View on Github external
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],
github jscad / OpenJSCAD.org / packages / examples / core / hulls / hullChain.js View on Github external
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)
    )
github jscad / OpenJSCAD.org / packages / examples / core / transforms / transformations.js View on Github external
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)
  ]
}
github jscad / OpenJSCAD.org / packages / examples / core / expansions / expand.js View on Github external
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,
github jscad / OpenJSCAD.org / packages / examples / core / expansions / expand.js View on Github external
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

  ]
github jscad / OpenJSCAD.org / packages / examples / core / expansions / expand.js View on Github external
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()
github jscad / OpenJSCAD.org / packages / examples / core / expansions / expand.js View on Github external
[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,
github jscad / OpenJSCAD.org / packages / examples / core / expansions / expand.js View on Github external
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)
  )
github jscad / OpenJSCAD.org / packages / examples / core / expansions / expand.js View on Github external
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,
github jscad / OpenJSCAD.org / packages / examples / core / hulls / hullChain.js View on Github external
/* 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 }
    )
  }