Book Image

Canvas Cookbook

Book Image

Canvas Cookbook

Overview of this book

With the growing popularity of HTML5 Canvas, this book offers tailored recipes to help you develop portable applications, presentations, and games. The recipes are simple yet creative and build on each other. At every step, the book inspires the reader to develop his/her own recipe. From basic to advanced, every aspect of Canvas API has been covered to guide readers to develop their own application, presentation, or game.
Table of Contents (16 chapters)
Canvas Cookbook
About the Author
About the Reviewer

Demonstrating composites

Composite operations allow you to change how the new content is drawn on an HTML5 <canvas> element. New things appear over whatever has already been drawn. By changing the global composite operation, you can draw new shapes behind existing ones, perform boolean operations, and do some other neat things.

The two main components in a compositing operation are the destination and the source. The destination is what is already on the canvas, and the source is what is getting drawn onto the canvas.

The following is a description for each possible composite operation available with the HTML5 Canvas API, where the text Be happy represents the source (S), and the green rectangle represents the destination (D). To further develop your understanding of composite operations, it helps to look at the corresponding operation while reading each description:



source-atop (S atop D)

Display the source image wherever both images are opaque. Display the...