November 2011
Intermediate to advanced
348 pages
7h 2m
English
In this recipe, we'll learn how to draw the only built-in shape provided by the HTML5 canvas API, a rectangle. As unexciting as a rectangle might seem, many applications use them in one way or another, so you might as well get acquainted.

Follow these steps to draw a simple rectangle centered on the canvas:
window.onload = function(){
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");rect() method, set the color fill with the fillStyle property, and then fill the shape with the fill() method:context.rect(canvas.width / 2 ...
Read now
Unlock full access