Shapes drawn in the canvas will start as lines. Lines are coloured by setting a strokeStyle
. If the lines close to make a solid area that may be coloured by setting a fillStyle
. In both cases there are several ways to specify colour. For now let's just use names.
There are a large number of colour names defined in the browser. They are listed here.
Having got the graphics context we set stroke and fill colours whenever we need to, like this:
g2.strokeStyle = "green";
g2.fillStyle = "yellow";
Note that the names are strings of characters and therefore appear in quotes. They are not keywords of the Javascript language.