-
Notifications
You must be signed in to change notification settings - Fork 278
Home
#Key Concepts of Maker.js
Maker.js lets you design shapes with JavaScript code. These shapes have only outlines. Shapes are made from primitive outlines called Paths. There are 3 primitive Paths: line, circle, and arc. Paths are defined by Points and other properties. A group of paths may be contained in what is called a Model. A Model may then contain other Models.
There is no concept of contiguity between paths.
POJO's: Plain old JavaScript objects are used to design your model. To make this work, these plain objects must conform to a schema.
{ x: number, y: number }
var myPoint = { x: 42, y: 99 };
All Path types require these properties at a minimum:
- type: string
- id: string
- origin: Point
Specific path types require additional properties:
{ type: "line", id: string, origin: Point, end: Point }
var myLine = {type:"line", id:"myLine1", origin:{x:0, y:0}, end:{x:42, y:99}};
{ type: "circle", id: string, origin: Point, radius: number }
var myCircle = {type:"circle", id:"myCircle1", origin:{x:0, y:0}, radius:13};
{ type: "arc", id: string, origin: Point, radius: number, startAngle: number, endAngle: number }
var myArc = {type:"arc", id:"myArc1", origin:{x:0, y:0}, radius:4.2, startAngle:45, endAngle:135};
Models require only an id property.
- id: string
Models may optionally contain these properties:
- type: string
- origin: Point
- paths: Array of Paths
- models: Array of Models
- units: string
The type property is currently not used, but it might be helpful for your own annotation to know where a model came from. The units property need not be specified, or it can be one of these values:
- "mm" for millimeter
- "cm" for centimeter
- "m" for meter
- "inch"
- "foot"
If your model contains a model with different units, you will want to Scale[link] it by a Unit Conversion[link] ratio.
Models may or may not contain paths. They also may or may not contain other models.
Therefore the minimum example of a model is:
{ id: string }
however this is pointless ;-)
var myModel = {id:"myModel1", paths:[myCircle, myLine, myArc]};
var myOtherModel = {id:"myModel2", paths:[{type:"circle", id:"myCircle2", origin:{x:0, y:0}, radius:3}]};
var allMyModels = {id:"allMyModels", models:[myModel , myOtherModel]};