From the course: Learning HTML Canvas

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

The canvas drawing context

The canvas drawing context

From the course: Learning HTML Canvas

Start my 1-month free trial

The canvas drawing context

- [Instructor] To actually draw things onto a canvas we need to use the canvas' drawing API and to do that, we need get a reference to something called The Canvas Drawing Context. In this course we're just going to be using two-dimensional drawing. So we'll be using the 2D context. There are other types of contexts that you can request. For example there's a context for 3D drawing using an API called WebGL, but that's a fairly advanced topic that could easily fill its own course, so we're just going to focus on 2D. Assuming we have a reference to a canvas element, we get the drawing context from it using the getContext method. And you can see here that the function is being called with the 2d string to indicate that we want to use the 2D drawing APIs. That function will return an object that implements the CanvasRenderingContext2D interface, which you can learn more about here in the MDN documentation. And you can see it's pretty comprehensive, there's a lot of methods and properties…

Contents