Malyan
Construction:
( params : Object )
Create a new instance of Malyan whereparamsis a object with several optional parameters listed below. The constructor also accepts no parameters at all.- id:
String | undefinedthe id of the canvas HTML tag. Optional; defaults toundefined. - dom:
HTMLElementthe HTML element of the canvas. Optional; defaults toundefined. - width:
Numberthe width of the canvas . Optional; defaults to300. - height:
Numberthe height of the canvas . Optional; defaults to150. - ratio:
Numberthe pixel ratio of the canvas. Optional; defaults to1. - autoRatio:
Booleanif autoRatio istrue, the value of ratio will be computed by devicePixelRatio. Optional; defaults totrue. - autoClear:
BooleanDefines whether the renderer should automatically clear its output before rendering a frame. Optional; defaults totrue. - background:
String | undefinedthe property of canvas style. Optional; defaults toundefined.
- id:
Members:
- id:
Numberthe same as above - dom:
Numberthe same as above - width:
Numberthe same as above - height:
Numberthe same as above - ratio:
Numberthe same as above - autoClear:
Booleanthe same as above - background:
String | undefinedthe same as above - ctx:
Objectcanvas context - config:
Objectconstruction arguments (width, height, ratio, autoRatio, autoClear, background...) - scene:
Objecta new instance of Scene - tree:
Objecta new instance of Tree - eventManager:
Objecta new instance of EventManager
- id:
Methods:
- getSize:
(): {width: Number, height: Number}
return width and height of canvas. - setSize:
(width: Number, height: Number): null
set width and height of canvas. - getPixelRatio:
(): Number
return current device pixel ratio used. - add:
(object: Object, ...): nulladd one or many shapes / groups to the instance. Objects can be added as arguments, new Malyan().add(o1, o2, oN), or as an array depicted above. - render:
(): null
render a scene. - forEach:
(callback: Function): null
traverse objects Deep First by the way of preOrder.
- getSize:
Example:
var canvas = new Malyan({ id: 'canvas', width: 500, height: 500, background: '#fff })
Scene
Extends: Group
Construction:
( params : Object )
Create a new instance of Scene.- root:
Malyanthe instance of Malyan.
- root:
Members:
- root:
Malyanthe same as above
- root:
Methods:
- render:
(): null
render objects.
- render:
Example:
this.scene = new Scene({ name: 'root_group', root: this })
Group
Extends: Shape
Construction:
( params : Object )
Create a new instance of Group.Members: the same as
ShapeMethods:
- render:
(): null
render the children of this group.
- render:
Shape
Extends: BaseObject && EventTarget
Construction:
( params : Object )
Create a new instance of Group whereparamsis a object with several optional parameters listed below. The constructor also accepts no parameters at all.- fill:
BooleanDefines whether fill the shape. Optional; defaults totrue. - stroke:
BooleanDefines whether stroke the shape. Optional; defaults totrue. - closed:
BooleanDefines whether close the path of shape. Optional; defaults tofalse. - fillStyle:
StringThe fillStyle property specifies the color, gradient, or pattern to use inside shapes. Optional; defaults to#fff. - strokeStyle:
StringThe strokeStyle property specifies the color, gradient, or pattern to use for the strokes (outlines) around shapes. Optional; defaults to#000. - lineWidth:
NumberThe lineWidth property sets the thickness of lines. Optional; defaults to1. - opacity:
NumberThe opacity property specifies the alpha (transparency) value that is applied to shapes and images before they are drawn onto the canvas. Optional; defaults to1. - shadowColor:
StringThe shadowColor property specifies the color of shadows. Optional; defaults torgba(0, 0, 0, 0). - shadowOffsetX:
NumberThe shadowOffsetX property specifies the distance that shadows will be offset horizontally. Optional; defaults to0. - shadowOffsetY:
NumberThe shadowOffsetX property specifies the distance that shadows will be offset vertically. Optional; defaults to0. - shadowBlur:
NumberThe shadowBlur property specifies the amount of blur applied to shadows. Optional; defaults to0. - lineCap:
StringThe lineCap("butt" || "round" || "square")property determines the shape used to draw the end points of lines. Optional; defaults tobutt. - lineJoin:
StringThe lineJoin("bevel" || "round" || "miter")property determines the shape used to join two line segments where they meet. Optional; defaults tomiter. - miterLimit:
NumberThe miterLimit property sets the miter limit ratio. Optional; defaults to10. - lineDash:
Array | undefinedUsed as arguments of the setLineDash() method of the Canvas 2D API. Sets the line dash pattern used when stroking lines. It uses an array of values that specify alternating lengths of lines and gaps which describe the pattern. Optional; defaults toundefined. - lineDashOffset:
NumberThe lineDashOffset property sets the line dash offset. Optional; defaults to0. - penetrable:
BooleanDefines whether target has effect when event occured. likepointer-events: nonein css. Optional; defaults tofalse. - onBeforeRender:
Functionhook execute before render. Optional; defaults to() => {}. - onAfterRender:
Functionhook execute after render. Optional; defaults to() => {}.
- fill:
Members:
- fill:
Booleanthe same as above - stroke:
Booleanthe same as above - closed:
Booleanthe same as above - fillStyle:
Stringthe same as above - strokeStyle:
Stringthe same as above - lineWidth:
Numberthe same as above - opacity:
Numberthe same as above - shadowColor:
Stringthe same as above - shadowOffsetX:
Numberthe same as above - shadowOffsetY:
Numberthe same as above - shadowBlur:
Numberthe same as above - lineCap:
Stringthe same as above - lineJoin:
Stringthe same as above - miterLimit:
Numberthe same as above - lineDash:
Array | undefinedthe same as above - lineDashOffset:
Numberthe same as above - penetrable:
Booleanthe same as above - onBeforeRender:
Functionthe same as above - onAfterRender:
Functionthe same as above - matrix:
Matrixa new instance of Matrix, calculated by_translation && _rotation && _scale - _translation:
Vectora new instance of Vector, determines the distance of translation - _scale:
Vectora new instance of Vector, determines the amount of scale - _rotation:
Numberdetermines the amount of rotation
- fill:
Methods:
- calcFinalMatrix:
(): Matrix
return this shape final matrix. - calcCanvasToPixelCoordinatePoint:
(targetPoint:[Number, Number]): relativePos:[Number, Number]
converts a point in the canvas coordinate system to the pixel coordinate system - calcPixelToCanvasCoordinatePoint:
(targetPoint:[Number, Number]): relativePos:[Number, Number]
converts a point in the pixel coordinate system to the canvas coordinate system - calcPixelToParentCoordinatePoint:
(targetPoint:[Number, Number]): relativePos:[Number, Number]
converts a point in the pixel coordinate system to the parent object coordinate system - calcParentToPixelCoordinatePoint:
(targetPoint:[Number, Number]): relativePos:[Number, Number]
converts a point in the parent object coordinate system to the pixel coordinate system - getRoot:
(): Malyan
return a Malyan instance (new Scene().root). - on:
(type: String, callback: Function): null
add event listener - dispatch:
(type: String, detail: Object): null
trigger event - off:
(type: String, callback: Function): null
remove event listener
- calcFinalMatrix:
Vector
Construction:
( params : Object )
Create a new instance of Vector.- x:
Numberthe amount of x-axis. Optional; defaults to0. - y:
Numberthe amount of y-axis. Optional; defaults to0. - onChange:
Functioncallback excute when x or y changed. Optional; defaults toundefined.
- x:
Members:
- x:
Numberthe same as above - y:
Numberthe same as above - onChange:
Functionthe same as above
- x:
Methods:
- set:
(x: Number, y: Number): null
set the value of x and y - static formatPointIntoVector:
(point: Array | Obeject): Vector
return a Vector instance from a point ([0, 0]or{x: 0, y: 0}).
- set:
BaseObject
Construction:
()Members:
- uuid:
Stringunique identifier - children:
Array - parent:
Object
- uuid:
Methods:
- add:
(object: Object, ...): nulladd one or many shapes to the instance. Objects can be added as arguments, new BaseObject().add(o1, o2, oN), or as an array depicted above. - remove:
(object: Object, ...): nullremove one or many shapes to the instance. Objects can be added as arguments, new BaseObject().remove(o1, o2, oN), or as an array depicted above.
- add:
EventTarget
Construction:
()Members:
- listeners:
Object
- listeners:
Methods:
- addEventListener:
(type: String, callback: Function): null
add event listener - dispatchEvent:
(type: String, event: CustomEvent): null
trigger event - removeEventListener:
(type: String, callback: Function): null
remove event listener
- addEventListener:
shapes
Rect
- Extends: Shape
Construction:
( params : Object )
Create a new instance of Vector.- x:
Numberthe x-axis value of left-top vertex. Optional; defaults to0. - y:
Numberthe y-axis value of left-top vertex. Optional; defaults to0. - width:
Numberthe width of rect. Optional; defaults to0. - height:
Numberthe height of rect. Optional; defaults to0. - center:
BooleanDefines whether the position of rect is in the center. Optional; defaults totrue.
- x:
Members:
- x:
Numberthe same as above - y:
Numberthe same as above - width:
Numberthe same as above - height:
Numberthe same as above - center:
Booleanthe same as above
- x:
Methods:
- render:
(ctx: CanvasRenderContext): null
render rect. - containPoint:
(ctx: CanvasRenderContext, point: {x: Number, y: Number}): Boolean
whether a point is inside of this rect. - getBoundingClientRect:
(): Object
return this rect bounding client params. (width, height, top, bottom, left, right) - getVertices:
(): Object
return this rect vertices.[[0,0], [1,1],...] - setCenter:
(): null
let this rect position to be in center.
- render: