How it Works: Painting the Canvas

In this lesson, we will discuss the workings of the exercise on the canvas tag from the previous exercise. Let's begin!

How it works

In step four, you defined the <canvas> tag and set it up with the “myCanvas” identifier. The page loads the drawing.js file in its <head> section, so the <script> placed right after the canvas knows the initDraw() function, and invokes it with the id of the canvas passed. The initDraw() function does all initialization, and it invokes the draw() method to paint the scenery:

Get hands-on with 1200+ tech skills courses.