Skip to content

Commit

Permalink
refactor(examples): overhauled module-design example for more clarity,
Browse files Browse the repository at this point in the history
better structure, and more idiomatic v2
  • Loading branch information
kaosat-dev committed Jan 28, 2020
1 parent 924047b commit d18a915
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
12 changes: 7 additions & 5 deletions packages/examples/core/module-design/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ const sphereShape = require('./subFolder/sphereShape')

const getParameterDefinitions = (prevParamValues) => {
return [
{ name: 'show', type: 'checkbox', checked: false, caption: 'Show:' },
{ name: 'showSphere', type: 'checkbox', checked: false, caption: 'Show sphere:' },
{ name: 'showPlate', type: 'checkbox', checked: true, caption: 'Show plate:' },
{ name: 'length', type: 'float', initial: 25, caption: 'length', min: 50, max: 200 }
]
}

const main = params => {
return [
mountPlate(params.length),
sphereShape(10)
]
let results = []
results = params.showPlate ? results.concat(mountPlate(params.length)) : results
results = params.showSphere ? results.concat(sphereShape(3)) : results

return results
}

module.exports = { main, getParameterDefinitions }
4 changes: 2 additions & 2 deletions packages/examples/core/module-design/mountPlate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { cube } = require('@jscad/modeling').primitives
const { cuboid } = require('@jscad/modeling').primitives

const mountPlate = (length) => {
return cube({ size: [length, 1, 1] })
return cuboid({ size: [length, 10, 1] })
}

module.exports = mountPlate
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { sphere } = require('@jscad/modeling').primitives
const color = require('@jscad/modeling').color.color

const sphereShape = (radius) => {
return sphere({ radius })
return color([1, 0, 0, 1], sphere({ radius }))
}

module.exports = sphereShape

0 comments on commit d18a915

Please sign in to comment.