Created
January 23, 2014 09:55
-
-
Save vforsh/8575880 to your computer and use it in GitHub Desktop.
Util for fast creating shapes in CreateJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///<reference path='../definitions/easeljs.d.ts' /> | |
| module qdrj { | |
| export class ShapeFactory { | |
| public static createRect(width:number, height:number, color:string = 'black', centered:boolean = true):createjs.Shape { | |
| var _x:number = centered ? width * 0.5 : 0; | |
| var _y:number = centered ? height * 0.5 : 0; | |
| var graphics:createjs.Graphics = new createjs.Graphics(); | |
| graphics.beginFill(color); | |
| graphics.drawRect(_x, _y, width, height); | |
| graphics.endFill(); | |
| return new createjs.Shape(graphics); | |
| } | |
| public static createCircle(radius:number, color:string = 'black', centered:boolean = true):createjs.Shape { | |
| var _x:number = centered ? radius * 0.5 : 0; | |
| var _y:number = centered ? radius * 0.5 : 0; | |
| var graphics:createjs.Graphics = new createjs.Graphics(); | |
| graphics.beginFill(color); | |
| graphics.drawCircle(_x, _y, radius); | |
| graphics.endFill(); | |
| return new createjs.Shape(graphics); | |
| } | |
| // TODO rework with thickness | |
| public static createCircleLine(radius:number, thickness:number = 1, color:string = 'black', centered:boolean = true):createjs.Shape { | |
| var _x:number = centered ? radius * 0.5 : 0; | |
| var _y:number = centered ? radius * 0.5 : 0; | |
| var graphics:createjs.Graphics = new createjs.Graphics(); | |
| graphics.beginStroke(color); | |
| graphics.drawCircle(_x, _y, radius); | |
| graphics.endStroke(); | |
| return new createjs.Shape(graphics); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment