sazr
sazr

Reputation: 25938

Draw a Stretched Arc on HTML5 Canvas

I know how to draw a partial circle(arc) on a HTML5 Canvas but how do I draw a stretched arc on a Canvas?

How do I draw an arc like the one below(where the arc is stetched/the radius changes)? enter image description here

This is how I draw a normal arc, maybe theres a function that can stretch this arc?

context.moveTo(centerX, centerY);
context.arc(centerX, centerY, radius, startingAngle, endingAngle, false);       
context.closePath();

Upvotes: 4

Views: 2824

Answers (2)

brainjam
brainjam

Reputation: 19005

You can use transforms. As in this live example.

context.save() ;
context.translate(150,150) ;
context.scale(2,1) ;
context.translate(-150,-150) ;
context.moveTo(150, 150);
context.arc(150, 150, 50, 0, 3*Math.PI/4, true);       
context.closePath();
context.stroke() ;
context.restore() ;
​

Upvotes: 3

Derek 朕會功夫
Derek 朕會功夫

Reputation: 94379

This is what you want: scale() in <canvas>

ctx.save();
ctx.scale(1,0.75);
//Do your arc here
ctx.restore();

//Viola!

DEMO: https://developer.mozilla.org/samples/canvas-tutorial/5_4_canvas_scale.html

Upvotes: 3

Related Questions