const { booleans, colors } = require('@jscad/modeling')

const { scission } = booleans
const { colorize, hslToRgb } = colors

// colorize all the shapes in the given list
const colorizeEach = (list) => {
  const t = 1 / list.length
  const newlist = list.map((shape, j) => {
    return colorize(hslToRgb([(t * (j + 1)), 1, 0.5, 0.8]), shape)
  })
  return newlist
}

// This example breaks apart the STL mesh into seperate spinners.
// The spinners can be exported as 3MF and printed in multiple colors.
const main = () => {
  const mesh = require('./airspinner2.stl')

  let spinners = scission(mesh)
  spinners = colorizeEach(spinners)

  return spinners
}

module.exports = { main }
