Skip to Content
HTML5 Canvas Cookbook
book

HTML5 Canvas Cookbook

by Eric Rowell
November 2011
Intermediate to advanced content levelIntermediate to advanced
348 pages
7h 2m
English
Packt Publishing
Content preview from HTML5 Canvas Cookbook

Creating custom shape functions: playing card suits

If a royal flush gets your adrenaline going, then this one's for you. In this recipe, we'll create drawing functions for the spade, heart, club, and diamond suits.

Creating custom shape functions: playing card suits

How to do it...

Follow these steps to draw a spade, heart, club, and diamond suit:

  1. Define the drawSpade() function which draws a spade with four Bezier curves, two quadratic curves, and one straight line:
    function drawSpade(context, x, y, width, height){ context.save(); var bottomWidth = width * 0.7; var topHeight = height * 0.7; var bottomHeight = height * 0.3; context.beginPath(); context.moveTo(x, y); // top left of spade context.bezierCurveTo( ...
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.
Start your free trial

You might also like

Foundation HTML5 Canvas

Foundation HTML5 Canvas

Rob Hawkes
HTML5 Canvas

HTML5 Canvas

Steve Fulton, Jeff Fulton

Publisher Resources

ISBN: 9781849691369Other