Drawing an ellipse in a Canvas is a common requirement, but most browsers have not yet implemented this method. Therefore, the arc or arcTo method is often used in combination with scale deformation to draw an ellipse, if you are interested, you can understand and hope to help you draw an ellipse in your Canvas, comparing the new HTML Canvas 2D Context W3C draft, the ellipse method is added to draw an ellipse, but this method has not been implemented by most browsers currently, so we need to use the arc or arcTo method combined with scale deformation to draw an ellipse.
Sample Code:
The Code is as follows:
Script
Var ctx = documentquerySelector ('canvas ') getContext ('2d ');
CtxlineWidth = "10 ";
Ctxscale (1, 2 );
Ctxarc (150,150,100, 0, MathPI * 2, false );
Ctxstroke ();
Script
A little wrong, because the line width is uneven, stroke is also affected by scale.
It requires a little skill to correct this problem.
Sample Code:
The Code is as follows:
[Code]
Script
Var ctx = documentquerySelector ('canvas ') getContext ('2d ');
CtxlineWidth = "10 ";
Ctxsave ();
Ctxscale (1, 2 );
Ctxarc (150,150,100, 0, MathPI * 2, false );
Ctxrestore ();
Ctxstroke ();
Script
[/Code]
Now it's even and perfect.
Tip: save the canvas state first, then zoom in and out, call the path command, restore the canvas state, and draw the stroke.
The key point is to save and zoom, restore first and then stroke.