Canvas of html5-code of drawing an arc and a rotating image + Rendering

Source: Internet
Author: User

Comments: Before performing the rotation operation, you must understand one sentence: rotation is the coordinate system of the canvas rather than the image itself. First, you must understand the coordinates of the circle: Center, start angle, and end angle; the next step is very simple. before performing the rotation operation, you must understand one sentence: rotation is the coordinate system of the canvas rather than the image itself. Well, after understanding this sentence, the next step is very simple.
First, let's take a look at the coordinates of the circle:
 

The Code is as follows:
<Script language = "javascript">
Var cxt = document. getElementById ('Demo'). getContext ("2d ");
Cxt. beginPath ();
Cxt. arc( 100,100, 50, Math. PI * 0.75, Math. PI * 1.75, false);/* draw a semi-circular arc with the Center Coordinate of 100,100; the start radian is 0.75, the end radian is 1.75, And the last parameter is False = clockwise, true = clockwise, of course, this parameter is optional */
Cxt. fillStyle = "# F00";/* select the color */
Cxt. fill ();/* draw the first half circle of a drawing on the canvas */
/* Draw the second half circle in the same way */
Cxt. beginPath ();
Cxt. arc (170,100, 50, Math. PI * 1.25, Math. PI * 0.25, false );
Cxt. fillStyle = "# F00 ";
Cxt. fill ();/* draw the drawing on the canvas */
Cxt. beginPath ();
/* Rotate the canvas 45 degrees clockwise. the parameter of the rotate function is radian, so conversion is required */
Cxt. rotate (45 * Math. PI/180 );
Cxt. fillRect (141.1,-50,100,100);/* Start coordinate is 141.1,-50, width and height are 100 */
Cxt. fillStyle = "# F00 ";
Cxt. fill ();
Cxt. beginPath ();
/* Rotate the canvas to a normal angle */
Cxt. rotate (-45 * Math. PI/180 );
Cxt. font = "60px ";
Cxt. strokeStyle = "# f00 ";
Cxt. strokeText ("I love html5", 0,300);/* two parameters: the first is the X axis coordinate of the text to be drawn, and the second is the Y coordinate of the text to be drawn */
Cxt. stroke ();
/* Create a gradient */
Var grd = cxt. createLinearGradient (,);/* four parameters are gradient start point x, y gradient end point x, y */
Grd. addColorStop (0, "# FF0000 ");
Grd. addColorStop (0.25, "# FFFF00 ");
Grd. addColorStop (0.5, "#00FF00 ");
Grd. addColorStop (0.75, "#00 FFFF ");
Grd. addColorStop (1, "# FFFF00 ");
Cxt. strokeStyle = grd;
Cxt. strokeText ("I love canvas", 0,400);/* two parameters: the first parameter is the X-axis coordinate of the text to be drawn, and the second parameter is the Y coordinate of the text to be drawn */
Cxt. stroke ();
</Script>

:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.