Book description
One of HTML5’s most exciting features, Canvas provides a powerful 2D graphics API that lets you implement everything from word processors to video games. In Core HTML5 Canvas, best-selling author David Geary presents a code-fueled, no-nonsense deep dive into that API, covering everything you need to know to implement rich and consistent web applications that run on a wide variety of operating systems and devices.
Succinctly and clearly written, this book examines dozens of real-world uses of the Canvas API, such as interactively drawing and manipulating shapes, saving and restoring the drawing surface to temporarily draw shapes and text, and implementing text controls. You’ll see how to keep your applications responsive with web workers when you filter images, how to implement smooth animations, and how to create layered, 3D scrolling backgrounds with parallax. In addition, you’ll see how to implement video games with extensive coverage of sprites, physics, collision detection, and the implementation of a game engine and an industrial-strength pinball game. The book concludes by showing you how to implement Canvas-based controls that you can use in any HTML5 application and how to use Canvas on mobile devices, including iOS5. This authoritative Canvas reference covers
The canvas element—using it with other HTML elements, handling events, printing a canvas, and using offscreen canvases
Shapes—drawing, dragging, erasing, and editing lines, arcs, circles, curves, and polygons; using shadows, gradients, and patterns
Text—drawing, positioning, setting font properties; building text controls
Images—drawing, scaling, clipping, processing, and animating
Animations—creating smooth, efficient, and portable animations
Sprites—implementing animated objects that have painters and behaviors
Physics—modeling physical systems (falling bodies, pendulums, and projectiles), and implementing tweening for nonlinear motion and animation
Collision detection—advanced techniques, clearly explained
Game development—all aspects of game development, such as time-based motion and high score support, implemented in a game engine
Custom controls—infrastructure for implementing custom controls; implementing progress bars, sliders, and an image panner
Mobile applications—fitting Canvas apps on a mobile screen, using media queries, handling touch events, and specifying iOS5 artifacts, such as app icons
Throughout the book, Geary discusses high-quality, reusable code to help professional developers learn everything they really need to know, with no unnecessary verbiage. All of the book’s code and live demonstrations of key techniques are available at corehtml5canvas.com.
Table of contents
- Title Page
- Copyright Page
- Contents
- Preface
- Acknowledgments
- About the Author
-
Chapter 1. Essentials
- 1.1. The canvas Element
- 1.2. Canvas Contexts
- 1.3. Canonical Examples in This Book
- 1.4. Getting Started
- 1.5. Fundamental Drawing Operations
- 1.6. Event Handling
- 1.7. Saving and Restoring the Drawing Surface
- 1.8. Using HTML Elements in a Canvas
- 1.9. Printing a Canvas
- 1.10. Offscreen Canvases
- 1.11. A Brief Math Primer
- 1.12. Conclusion
-
Chapter 2. Drawing
- 2.1. The Coordinate System
- 2.2. The Drawing Model
- 2.3. Drawing Rectangles
- 2.4. Colors and Transparency
- 2.5. Gradients and Patterns
- 2.6. Shadows
- 2.7. Paths, Stroking, and Filling
- 2.8. Lines
- 2.9. Arcs and Circles
- 2.10. Bézier Curves
- 2.11. Polygons
- 2.12. Advanced Path Manipulation
- 2.13. Transformations
- 2.14. Compositing
- 2.15. The Clipping Region
- 2.16. Conclusion
- Chapter 3. Text
- Chapter 4. Images and Video
-
Chapter 5. Animation
- 5.1. The Animation Loop
- 5.2. Calculating Frame Rates
- 5.3. Scheduling Tasks at Alternate Frame Rates
- 5.4. Restoring the Background
- 5.5. Double Buffering
- 5.6. Time-Based Motion
- 5.7. Scrolling the Background
- 5.8. Parallax
- 5.9. User Gestures
- 5.10. Timed Animations
- 5.11. Animation Best Practices
- 5.12. Conclusion
- Chapter 6. Sprites
- Chapter 7. Physics
- Chapter 8. Collision Detection
- Chapter 9. Game Development
- Chapter 10. Custom Controls
- Chapter 11. Mobile
- Index
Product information
- Title: Core HTML5 Canvas: Graphics, Animation, and Game Development
- Author(s):
- Release date: May 2012
- Publisher(s): Pearson
- ISBN: 9780132761635
You might also like
book
Physics for JavaScript Games, Animation, and Simulations: with HTML5 Canvas
Have you ever wanted to include believable physical behaviors in your games and projects to give …
book
HTML5 Canvas, 2nd Edition
Flash is fading fast as Canvas continues to climb. The second edition of this popular book …
book
Core HTML5 2D Game Programming
Game programming offers a wealth of creative and business opportunities, and it’s never been more accessible. …
book
CSS Animations and Transitions for the Modern Web
Modern websites use a variety of animated effects not only to improve usability but also to …