Mastering HTML5 Canvas walks you through the fascinating arena of web development, covering all the critical concepts of drawing and manipulating pixels in the canvas through tons of examples and designs.
We start the course off by introducing the foundations of the canvas API. You’ll learn how to create canvas elements dynamically and draw basic shapes, and you’ll get familiar with the work environment. Then we shift our focus on to drawing, where you will draw lines, original shapes, paths, and even multiple pointed shapes.
Next, we’ll then leverage the logic that stands behind the cosine and sine functions and through them, create more complicated shapes. This new insight will enable you to create more complex and advanced shape combinations. We will continue our journey by getting to grips with the various types of curves, images, and gradient colors. Finally, we will deal with manipulation of the canvas itself.
By the end of this course, you will know how to draw in HTML5 canvas, create complex shapes, and use angles, arcs, and curves to create your own art work. You will be a master of the HTML5 2D canvas API.
About The Author
Ben Fhala discovered his passion for data visualization while he was working at Parsons in New York, in their data visualization department, PIIM. He is the owner of the online video training school and an Adobe ACP. He enjoys spending most of his time learning and teaching, and has a love for visual programming and visualization in general. Ben has had the honor of developing applications for members of the US Congress, Prime Ministers, and Presidents around the world.
He has built many interactive experiences for companies such as Target, AT&T, Crayola, Marriott, Neutrogena, and Nokia. He has technically directed many award-winning projects and has been part of teams that have won three Agency of the Year awards.
This video will offer an overview of the course.
Although most modern browsers support Canvas, not all of them do so. While we won't create an optimal experience for users without the HTML5 Canvas support, we want to create a graceful fallback experience. So, before we start our journey into Canvas, we will prepare our source files to accommodate failures.
We start our canvas journey by creating a simple rectangle in the process. We will learn how to define the Canvas size, a fill style, and how to fill it up using the fillRect method.
In this video, we will continue working with the flag creation we started in the last video. By the end of this video, we will have created the complete flag of Palau along with a perfect arc—more commonly known as a circle.
Up until now, we worked with the Canvas element that we added onto the stage manually. We will now learn how to dynamically add new Canvas elements into our HTML.
We learned as we created the flag for Palau that when we create a circle using the arc method, we have to trigger a request separately to fill the shape. This is true for all shapes that we create from scratch, and it is true for the creation of lines as well. In this video, we shift our attention to lines.
In the previous video we, started to create the flag of Greece. We are still short on a few lines of code to complete this flag, but before we can complete creating the flag, we'll encounter another new concept—paths. By the end of this video, you will understand how to work with paths in HTML5 Canvas.
In this video, we will take advantage of the new method we were introduced to in the previous video, beginPath, to define a path. Only this time, we will define this path as a closed path. By the end of this video, you will know how to work with the beginPath and closePath methods and create your own geometric shapes.
In this video, we will take advantage of the new utility function that we created in the previous video to create the flag of Guyana. In the process, we will learn how to create relative designs that can easily scale.
In this video, we continue down the road while creating a multishaped object. By the end of this video, you will have a deep understanding of how to work with paths to create complex shapes.
As you start to develop more complex shapes, you will need to take advantage of the sine and cosine functions to create complex shapes and animations. In this video, we will revisit the basics of working with sine and cosine as we get ready to build an analog clock flag.
Now that we know the basics of working with Math.sin and Math.cos, it's time for us to continue and develop a clicking analog clock.
It's time to take everything we learned and integrate it into the most complex shape we have seen so far, the Star of David. This star is part of the flag of Israel, and to create it, we will need to use our triangle, sine, and the cosine logic.
There are many flags that contain stars that just cannot be created by overlapping triangles. In this video, we will figure out how to create a star that contains an arbitrary number of points. We will create the flag of Somalia, and in the process, we'll figure out how to create a function that will enable us to create stars.
There are many flags and shapes, in general that can be created by combining the shapes we've created so far. One of the most popular shapes in 82 flags that we don't know how to create is the crescent shape, similar to the one in the flag of Turkey. With it, we learn a new skill that uses subtraction to create more in-depth shapes.
There are three types of curves that we can create in Canvas—using the arc, quadratic curves, and Bezier curves. In this video, we will shift our attention to the arc again, and, this time, we'll really master its full capabilities. At the end of this video, we will create a pacman and a pie chart example.
A quadratic curve is one that has a control point. Consider the case when creating a line; we draw it between two points. When we want to create a quadratic curve, we use an external gravity controller that defines the direction of the curve, while the middle line (the dotted line) defines how far the curve will reach. Let’s learn about this.
A bezier curve is one that has two control points. When we want to create a bezier curve, we use two external gravity controllers that define the direction of the curve while one control is on one side and the other is on the other side of the bounded area.
Let's turn our attention to Haiti and get their flag up and running. To create this flag, we need to have the image of the symbol that is placed in the center of the flag. In this video, we will learn how to add images into Canvas, resize them, and how to maintain their original ratio.
Since we started our course, all the colors we used were solid colors. It's time for us to take a look at gradients. By the end of this video, you will know how to work with linear gradients.
In this video, we will explore a more complex type of gradient—a radial gradient. You will learn how to create with it, understand how to control the two anchor points, and the radius of the gradient.
Although the main usage of Canvas is to draw, at times, you might need to add text to canvas. To do this, we will take advantage of a few build int methods and properties of the canvas 2D API.
Canvas items, when rendered, are represented as bitmap data, and as such, the Canvas API comes with a way for us to manipulate data on the bitmap level. By the end of this video, you will know how to fetch the pixel data and manipulate it.
Like any modern drawing editor, the canvas API, too, provides a means to create masking in Canvas. Masking is done using the clip method. In this video, we will learn how to work with the clip method.
Throughout this course, all our manipulations have been targeted at the items that were drawn. In the previous video, we moved to a type of transformation that focused on the Canvas itself, and in the next two videos, we will continue down this path. In this video, we will learn how to transform the Canvas.
To wrap up this course, we are going to cover the three final and major methods that manipulate the full Canvas.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.