meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:design_guide_anatomy [2020/11/28 02:08]
JSCAD Editor created
en:design_guide_anatomy [2020/12/08 06:41] (current)
JSCAD Editor
Line 1: Line 1:
 ===== Anatomy of a Design ===== ===== Anatomy of a Design =====
-A JSCAD script must have at least one function defined, the **main()** function, which must to return a shape.+ 
 +A JSCAD design (scriptmust have at least one function defined, the **main()** function, which must to return a shape. 
 <code javascript> <code javascript>
-function main() {+const { sphere } = require('@jscad/modeling').primitives 
 + 
 +const main () => {
   return sphere() // a single shape   return sphere() // a single shape
 } }
 +
 +module.exports = { main }
 </code> </code>
 +
 Or an array of shapes. Or an array of shapes.
 +
 <code javascript> <code javascript>
-function main() {+const { cube, cylinder, sphere } = require('@jscad/modeling').primitives 
 + 
 +const main () => {
   const a = cube()   const a = cube()
   const b = sphere()   const b = sphere()
Line 14: Line 24:
   return [a,b,c] // an array of shapes   return [a,b,c] // an array of shapes
 } }
 +
 +module.exports = { main }
 </code> </code>
-In addition, functions can be created and called, i.e. normal JavaScript.+ 
 +In addition, functions can be created to split the design into managable pieces, i.e. parts, etc. 
 <code javascript> <code javascript>
-function a(options) { // passed from main() below +const { cube, sphere } = require('@jscad/modeling').primitives 
-  var = [] + 
-  w.push( sphere() ) +const partA = (options) => { // called from main() below 
-  w.push( cube(options).translate([2,0,0]) ) +  var shapes = [] 
-  return w+  shapes.push( sphere() ) 
 +  shapes.push( cube(options) ) 
 +  return shapes
 } }
-function main() { + 
-  let list = a({radius: 10})+const main () => 
 +  let list = partA({radius: 10})
   return list   return list
 } }
 +
 +module.exports = { main }
 </code> </code>