HTML 5 Canvas

No matter what platform or tools you use, the HTML5 revolution will soon change the way you build web applications, if it hasn't already. HTML5 is jam-packed with features, and there's a lot to learn. This book gets you started with the Canvas element, perhaps HTML5's most exciting feature. This book gets you started with the Canvas element, perhaps HTML5's most exciting feature. Learn how to build interactive multimedia applications using this element to draw, render text, manipulate images, and create animation.

Whether you currently use Flash, Silverlight, or just HTML and JavaScript, you'll quickly pick up the basics. Practical examples show you how to create various games and entertainment applications with Canvas as you learn. Gain valuable experience with HTML5, and discover why leading application developers rave about this specification as the future of truly innovative web development.

  • Create and modify 2D drawings, text, and bitmap images
  • Incorporate and manipulate video, and add audio
  • Build a basic framework for creating a variety of games on Canvas
  • Use bitmaps and tile sheets to develop animated game graphics
  • Go mobile: port Canvas applications to iPhone with PhoneGap
  • Explore ways to use Canvas for 3D and multiplayer game applications



Table of Contents

  1. Chapter 1 Introduction to HTML5 Canvas
    1. The Basic HTML Page
    2. Basic HTML We Will Use in This Book
    3. The Document Object Model (DOM) and Canvas
    4. JavaScript and Canvas
    5. HTML5 Canvas “Hello World!”
    6. Debugging with Console.log
    7. The 2D Context and the Current State
    8. The HTML5 Canvas Object
    9. Another Example: Guess The Letter
    10. What’s Next
  2. Chapter 2 Drawing on the Canvas

    1. The Basic File Setup for This Chapter
    2. The Basic Rectangle Shape
    3. The Canvas State
    4. Using Paths to Create Lines
    5. Advanced Path Methods
    6. Compositing on the Canvas
    7. Simple Canvas Transformations
    8. Filling Objects with Colors and Gradients
    9. Filling Shapes with Patterns
    10. Creating Shadows on Canvas Shapes
    11. What’s Next
  3. Chapter 3 The HTML5 Canvas Text API
    1. Displaying Basic Text

    2. Setting the Text Font

    3. Text and the Canvas Context

    4. Text with Gradients and Patterns

    5. Width, Height, Scale, and toDataURL() Revisited

    6. Final Version of Text Arranger

    7. What’s Next

  4. Chapter 4 Images on the Canvas

    1. The Basic File Setup for This Chapter

    2. Image Basics

    3. Simple Cell-Based Sprite Animation

    4. Advanced Cell-Based Animation

    5. Applying Rotation Transformations to an Image

    6. Creating a Grid of Tiles

    7. Zooming and Panning an Image

    8. Pixel Manipulation

    9. Copying from One Canvas to Another

    10. What’s Next

  5. Chapter 5 Math, Physics, and Animation

    1. Moving in a Straight Line

    2. Bouncing Off Walls

    3. Curve and Circular Movement

    4. Simple Gravity, Elasticity, and Friction

    5. Easing

    6. What’s Next?

  6. Chapter 6 Mixing HTML5 Video and Canvas

    1. HTML5 Video Support

    2. Converting Video Formats

    3. Basic HTML5 Video Implementation

    4. Preloading Video in JavaScript

    5. Video and the Canvas

    6. Video on the Canvas Examples

    7. Animation Revisited: Moving Videos

    8. What’s Next?

  7. Chapter 7 Working with Audio
    1. The Basic