How to use the @jscad/modeling.color function in @jscad/modeling

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 / 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 / parameters / stepper-motor.js View on Github external
const length = parameters.motorBody_len / 2
  const width = parameters.motorBody_width / 2
  const ch = sqrt(2.0) * width - sqrt(0.5) * parameters.motorBody_chamfer
  const ch2 = sqrt(2.0) * width - sqrt(0.5) * parameters.motorCap_chamfer
  const depth = parameters.mountingholes_depth
  const offset = parameters.mountingholes_fromcent

  const cubeColor = [0.67843137254901960784313725490196, 0.70588235294117647058823529411765, 0.70588235294117647058823529411765]
  const fooColor = [0.87058823529411764705882352941176, 0.89803921568627450980392156862745, 0.90588235294117647058823529411765]
  let body = CSG.roundedCube({
    center: [0, 0, 0],
    radius: [length - parameters.motorCap_len, width - parameters.motorCap_thickness, width - parameters.motorCap_thickness],
    roundradius: 0.2,
    resolution: 16
  })
  body = color(cubeColor, body)
  let xcube = cube({
    center: [0, 0, 0],
    radius: [length, ch, ch]
  })
  xcube = color(cubeColor, xcube)
  body = intersect(body, rotateX(degToRad(45), xcube))

  var cube2 = CSG.roundedCube({
    center: [length - (parameters.motorCap_len / 2.0), 0, 0],
    radius: [(parameters.motorCap_len / 2.0), width, width],
    roundradius: 0.2,
    resolution: 16
  })
  cube2 = cube2.setColor(fooColor)
  var cube3 = cube2.translate([-(parameters.motorBody_len - parameters.motorCap_len), 0, 0])
  xcube = cube({
github jscad / OpenJSCAD.org / packages / examples / parameters / stepper-motor.js View on Github external
const offset = parameters.mountingholes_fromcent

  const cubeColor = [0.67843137254901960784313725490196, 0.70588235294117647058823529411765, 0.70588235294117647058823529411765]
  const fooColor = [0.87058823529411764705882352941176, 0.89803921568627450980392156862745, 0.90588235294117647058823529411765]
  let body = CSG.roundedCube({
    center: [0, 0, 0],
    radius: [length - parameters.motorCap_len, width - parameters.motorCap_thickness, width - parameters.motorCap_thickness],
    roundradius: 0.2,
    resolution: 16
  })
  body = color(cubeColor, body)
  let xcube = cube({
    center: [0, 0, 0],
    radius: [length, ch, ch]
  })
  xcube = color(cubeColor, xcube)
  body = intersect(body, rotateX(degToRad(45), xcube))

  var cube2 = CSG.roundedCube({
    center: [length - (parameters.motorCap_len / 2.0), 0, 0],
    radius: [(parameters.motorCap_len / 2.0), width, width],
    roundradius: 0.2,
    resolution: 16
  })
  cube2 = cube2.setColor(fooColor)
  var cube3 = cube2.translate([-(parameters.motorBody_len - parameters.motorCap_len), 0, 0])
  xcube = cube({
    center: [0, 0, 0],
    radius: [length, ch2, ch2]
  })
  xcube = color(fooColor, xcube)
  xcube = rotateX(degToRad(45), xcube)
github jscad / OpenJSCAD.org / packages / examples / parameters / stepper-motor.js View on Github external
end: [length + parameters.motorRing_height, 0, 0],
      radius: parameters.motorRing_radius,
      resolution: 100
    })
  )

  const shaft = color([0.9, 0.91, 0.91],
    cylinder({
      start: [length + parameters.motorRing_height, 0, 0],
      end: [length + parameters.motorRing_height + parameters.shaft_len, 0, 0],
      radius: parameters.shaft_radius,
      resolution: 50
    })
  )

  const mountinghole = color([0.2, 0.2, 0.2],
    cylinder({
      start: [-depth, 0, 0],
      end: [0, 0, 0],
      radius: parameters.mountingholes_radius,
      resolution: 20
    })
  )

  let motor = union([cube, cube2, cube3, ring, shaft])
  motor = motor.subtract(
    translate([length, offset, offset], mountinghole),
    translate([length, offset, -offset], mountinghole),
    translate([length, -offset, offset], mountinghole),
    translate([length, -offset, -offset], mountinghole)
  )
github jscad / OpenJSCAD.org / packages / examples / parameters / stepper-motor.js View on Github external
radius: [length, ch2, ch2]
    }),
    color(fooColor),
    rotateX(45)
  ) */

  const ring = color([0.81176470588235294117647058823529, 0.84313725490196078431372549019608, 0.85098039215686274509803921568627],
    cylinder({
      start: [length, 0, 0],
      end: [length + parameters.motorRing_height, 0, 0],
      radius: parameters.motorRing_radius,
      resolution: 100
    })
  )

  const shaft = color([0.9, 0.91, 0.91],
    cylinder({
      start: [length + parameters.motorRing_height, 0, 0],
      end: [length + parameters.motorRing_height + parameters.shaft_len, 0, 0],
      radius: parameters.shaft_radius,
      resolution: 50
    })
  )

  const mountinghole = color([0.2, 0.2, 0.2],
    cylinder({
      start: [-depth, 0, 0],
      end: [0, 0, 0],
      radius: parameters.mountingholes_radius,
      resolution: 20
    })
  )