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