Skip to content

Instantly share code, notes, and snippets.

@vforsh
Created January 23, 2014 09:55
Show Gist options
  • Select an option

  • Save vforsh/8575880 to your computer and use it in GitHub Desktop.

Select an option

Save vforsh/8575880 to your computer and use it in GitHub Desktop.
Util for fast creating shapes in CreateJS
///<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