Preface.
1. Introduction to HIML5 Canvas
What Is HTML5?
The Basic HTML'S Page
cklodype html>
<html lang-“en”>
'' i ne t a oh a rse t - “IT LI' ТГ' -
< t ill e>...</title >
A Simple HTML5 Page Basic HTMI, We Will Use in This Book <div>
< can vase
The Document Object Model (DOM) and < anvas JavaScript and Canvas Where Does JavaScript Co and Why?
IITML5 Canvas “Hello World!”
Encapsulating Your JavaScript Code lor (lanvas Adding Canvas to the HTML Page
Using the document Object to Releience the Canvas LDment in JavaScript Testing to See Whether the (bowser Supports (lanvas
Retrieving the 2D Context The dravvScreenO Function Debugging with console.log The 2D Context and the Current Slate The HTMI,5 Canvas (Abject Another Example: Guess The l etter How the Game Works The “Guess The heller” (lame Variables
2. Di.p./imj on tip ( :nv i, , . ..................
1 Ilf I’afik i ilt V'Uip an 1 ha. 1 h iplal d Ik Ha ,k H . 1 m,L Sh.tPi 1 hi t an\ J‘ Sink W'h its Uni i’M.ol iht 3n4w litn. 1m '\t 4a\t and Kesto e di ‘ (smvas Sluter Using Paths to t l rata l lnt •. dlai lHip anil hiding a faili 1 In iu.il 1 nawing
1 maple, oi Minn A Kami.i I ilk Drawing Ad1 aik . d 1 ath a K tla"h
A res
Bezier Curves
The Canvas Clipping Region (iornposiiing on the Canvas Sinip 1 e (.1 anvas Irans 1 orrna 1 ions Rotation and Translation Transformations Scale Transformations
Combining Scale and Rotation Transformations lulling Objects with Colors and Gradients Setting Basic hill Colors Filling Shapes with Gradients lulling Shapes with Patterns Creating Shadows on Canvas Shapes Methods to Clear the Canvas Simple lull
Resetting the Canvas Width and Height 77
Resetting the Canvas clearRect Function 77
Checking to See Whether a Point Is in the Current Path 7У
Drawing a Focus Ring go
What’s Next? gg
3. The HTML5 Canvas Text API, 81
Canvas Text and CSS , g]
Displaying Basic Text 82
Basic Text Display 82
Handling Basic Text in Text Arranger 82
Communicating Between HTML Forms and the Canvas 83
Using measureText g.j
tillText and strokeText 85
Setting the Text Font go
Font Size, Face, Weight, and Style Basics go
Handling Font'Size and Face in Text Arranger 89
Font Color 94
Font Baseline and Alignment 90
Text Arranger Version 2.0 101
Text and the Canvas Context j Q(
Global Alpha and Text 10 j
Global Shadows and Text KB
Text with Gradients and Patterns 106
Linear Gradients and Text 107
Radial Gradients and Text - 100
Image-Patterns and-Text ■ • 109
Handling Gradients and Patterns in Text Arranger 1 it)
Width, Height, Scale, and toDuialJRLO Revisited 1 14
Dynamically Resizing the Canvas 114
Dynamically Scaling the Canvas 1 15
The toDatalJRLQ Method of the Canvas Object 1 17
Final .Version of Text Arranger ) 19
Animated Gradients 128
The Future of Text on tlie Canvas ' 132
CSS Text 133
Making Text Accessible ’ 133
What’s Next? \ 33
4, Images on the Canvas. 135
The Basic File Setup for This Chapter 135
image Basics 136