THE 2D CONTEXT
The 2D drawing context provides methods for drawing simple 2D shapes such as rectangles, arcs, and paths. The coordinates in a 2D context begin at the upper-left of the <canvas>
element, which is considered point (0, 0). All coordinate values are calculated in relation to that point, with x increasing to the right and y increasing toward the bottom. By default, the width
and height
indicate how many pixels are available in each direction.
Fills and Strokes
There are two basic drawing operations on the 2D context: fill and stroke. Fill automatically fills in the shape with a specific style (color, gradient, or image) while stroke colors only the edges. Most of the 2D context operations have both fill and stroke variants, and how they are displayed is based on a couple of properties: fillStyle
and strokeStyle
.
Both properties can be set to a string, a gradient object, or a pattern object, and both default to a value of "#000000". A string value indicates...