Game Development Reference
In-Depth Information
Shapes are only drawn after the call to stroke(), at which point the current style attributes are used.
Shapes
There are a couple of different shapes we can draw very effortlessly. These are rect-
angles and circles. While, there is no circle function as there is a rect function for
drawing rectangles. There is, however, an arc function, from which we can draw
circles.
The rect function takes four parameters, exactly as fillRect . arc takes an x and
a y coordinate, followed by a radius, a starting angle (in radians, not degrees), an
ending angle, and a Boolean, specifying, if the arc is to be drawn clockwise. To draw
a circle, we can just draw an arc that goes from 0 to PI times 2, which is the same as
360 degrees.
ctx.fillStyle = "#fff";
ctx.strokeStyle = "#c0c";
Search WWH ::




Custom Search