meta data for this page
Differences
This shows you the differences between two versions of the page.
| 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 (script) must have at least one function defined, the **main()** function, which must to return a shape. | ||
| <code javascript> | <code javascript> | ||
| - | function | + | const { sphere } = require(' |
| + | |||
| + | const main = () => { | ||
| return sphere() // a single shape | return sphere() // a single shape | ||
| } | } | ||
| + | |||
| + | module.exports = { main } | ||
| </ | </ | ||
| + | |||
| Or an array of shapes. | Or an array of shapes. | ||
| + | |||
| <code javascript> | <code javascript> | ||
| - | function | + | const { cube, cylinder, sphere } = require(' |
| + | |||
| + | 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 } | ||
| </ | </ | ||
| - | In addition, functions can be created | + | |
| + | In addition, functions can be created | ||
| <code javascript> | <code javascript> | ||
| - | function a(options) { // passed | + | const { cube, sphere } = require(' |
| - | var w = [] | + | |
| - | | + | const partA = (options) |
| - | | + | var shapes |
| - | return | + | |
| + | | ||
| + | return | ||
| } | } | ||
| - | function | + | |
| - | let list = a({radius: 10}) | + | const main = () => { |
| + | let list = partA({radius: 10}) | ||
| return list | return list | ||
| } | } | ||
| + | |||
| + | module.exports = { main } | ||
| </ | </ | ||