Jump Start HTML5 by Tiffany B. Brown Kerry Butters Sandeep Panda

Jump Start HTML5 by Tiffany B. Brown Kerry Butters Sandeep Panda

Author:Tiffany B. Brown, Kerry Butters, Sandeep Panda [Brown, Tiffany B.]
Language: eng
Format: epub, mobi
ISBN: 9780980285826
Publisher: SitePoint Pty. Ltd.
Published: 2014-03-30T16:00:00+00:00


Canvas uses a two-dimensional coordinates grid. The top-left of the canvas has a coordinate of (0,0). The bottom-right will have a positive x and y coordinate according to the size of the element. In the example above, we used a canvas size of 300x150px, so the bottom-right pixel is at (299,149), because coordinates are zero-based.

Lines are drawn on the canvas using paths. You create paths by using the moveTo() and lineTo() methods, in conjunction with one of the ink methods, stroke() or fill(). moveTo() and lineTo() define the start and end points of the line to be drawn. stroke() draws a shape by "stroking" its outline, while fill() draws a solid shape by filling in the content area of a path.

So, to draw a simple white line through the rectangle we created above:

ctx.strokeStyle = "#FFFFFF"; ctx.beginPath(); ctx.moveTo(0,0); ctx.lineTo(300,150); ctx.stroke();

The beginPath method erases any outstanding path drawing operations in preparation for a new path. The stroke() method physically draws the path you've defined. In this case, it's a single line.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.