JavaScript Intensive Tutorial--canvas

Source: Internet
Author: User

This article ish5eduAgency officialHTML5 Trainingtutorials, the main introduction:JavaScript Intensive Tutorials--canvas

Use Stroketext (): Use the "Arial" font to draw a high 30px text (hollow) on the canvas: Javascript:var C=document.getelementbyid ("MyCanvas"); var ctx= C.getcontext ("2d"); ctx.font= "30px Arial"; Ctx.stroketext ("Hello World", 10,50); Canvas-gradient gradients can be filled in rectangles, circles, lines, text, and so on, and various shapes can define different colors themselves. There are two different ways to set up the canvas gradient: createlineargradient (x,y,x1,y1)-Create a line gradient createradialgradient (X,Y,R,X1,Y1,R1)-Create a radial/ Circle Gradient When we use a Gradient object, you must use two or more stop colors. The Addcolorstop () method specifies that the color stops, and the parameters are described using coordinates, which can be 0 to 1. Using gradients, set the value of FillStyle or Strokestyle as a gradient, and then draw a shape, such as a rectangle, text, or a line. Use Createlineargradient (): Create a linear gradient. Fill the rectangle with a gradient: Javascript:var C=document.getelementbyid ("MyCanvas"), Var ctx=c.getcontext ("2d");//Create Gradientvar grd= Ctx.createlineargradient (0,0,200,0); Grd.addcolorstop (0, "Red"); Grd.addcolorstop (1, "white");//Fill with Gradientctx.fillstyle=grd;ctx.fillrect (10,10,150,80);

Click to enter JavaScript intensive tutorial

This article is from the "11721999" blog, please be sure to keep this source http://11731999.blog.51cto.com/11721999/1860053

JavaScript Intensive Tutorial--canvas

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.