Skip to Content
HTML5 Games: Creating Fun with HTML5, CSS3 and WebGL, 2nd Edition
book

HTML5 Games: Creating Fun with HTML5, CSS3 and WebGL, 2nd Edition

by Jacob Seidelin
March 2014
Beginner to intermediate
456 pages
8h 44m
English
Wiley
Content preview from HTML5 Games: Creating Fun with HTML5, CSS3 and WebGL, 2nd Edition

Chapter 6

Creating Graphics with Canvas

In This Chapter

• Using canvas versus other methods

• Drawing with the canvas element

• Drawing paths and shapes

• Applying transformations to the canvas

• Modifying image data

THIS CHAPTER SHOWS you how to create dynamic graphics with the canvas element. It starts by giving you an overview of the ways in which you can display graphics and graphics on the web before diving into the canvas drawing API.

The meat of this chapter is all about how to use the canvas API. First, you walk through the basics of drawing simple shapes and paths and applying various styles to the content. You learn how to use the canvas state stack to your advantage and see how to mix images and text content with graphics on the canvas.

Then you learn how to use transformations to modify the way things are drawn and how to apply different compositing operations. Finally, the chapter rounds off the canvas tour by looking at how to use low-level pixel access to create some really interesting effects.

Ways to Display Graphics on the Web

In the past, all graphics on the web had to be represented by bitmap images in formats such as GIF or JPEG. More options for displaying graphics on the web are available today.

Bitmap images

Bitmaps are images defined by a rectangular grid of pixels. The traditional formats used on the web—JPEG, PNG, and GIF—are all bitmap formats. Bitmaps are perfectly adequate for many purposes. In some cases, such as displaying photos, they are the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Making Isometric Social Real-Time Games with HTML5, CSS3, and JavaScript

Making Isometric Social Real-Time Games with HTML5, CSS3, and JavaScript

Mario Andres Pagella

Publisher Resources

ISBN: 9781118855454Purchase book