Posts

Showing posts with the label ellipse

ellipse and circle for canvas 2d context

These days I am working inside an ExtJS panel to create some sophisticated drawing stuff, and I discovered (too late ...) that there is almost nothing in canvas 2d context to draw circle or ellipse. That's why I have extended Google excanvas library and/or native canvas 2d context prototype to let us create circles and ellipse in the same simple way we can create rectangles. Here the extended proto: (function(){ // Andrea Giammarchi - Mit Style License var extend = { // Circle methods circle:function(aX, aY, aDiameter){ this.ellipse(aX, aY, aDiameter, aDiameter); }, fillCircle:function(aX, aY, aDiameter){ this.beginPath(); this.circle(aX, aY, aDiameter); this.fill(); }, strokeCircle:function(aX, aY, aDiameter){ this.beginPath(); this.circle(aX, aY, aDiameter); this.stroke(); }, // Ellipse methods ellipse:function(aX, aY, aWidth, aHeight){ var hB = (aWidth / 2) * .5522848, ...