简体   繁体   English

在HTML5 Canvas上绘制拉伸弧

[英]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? 我知道如何在HTML5 Canvas上绘制局部圆(弧),但如何在Canvas上绘制拉伸弧?

How do I draw an arc like the one below(where the arc is stetched/the radius changes)? 如何绘制如下所示的弧线(弧线被瞄准/半径变化)? 在此输入图像描述

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();

This is what you want: scale() in <canvas> 这就是你想要的: <canvas> scale()

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 演示: https//developer.mozilla.org/samples/canvas-tutorial/5_4_canvas_scale.html

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() ;
​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM