HTML Canvas Heart, Spade, Club, Diamond

by Arjan Haverkamp

HTML

<!--   w w  w. j a  v a  2s  . c o m-->
<html>
    <head>
        <script>
            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(
          x, y + topHeight / 2, // control point 1
                x - width / 2, y + topHeight / 2, // control point 2
                x - width / 2, y + topHeight // end point
              );
                
                // bottom left of spade
                context.bezierCurveTo(
          x - width / 2, y + topHeight * 1.3, // control point 1
                x, y + topHeight * 1.3, // control point 2
                x, y + topHeight // end point
              );
                
                // bottom right of spade
                context.bezierCurveTo(
          x, y + topHeight * 1.3, // control point 1
                x + width / 2, y + topHeight * 1.3, // control point 2
                x + width / 2, y + topHeight // end point
              );
                
                // top right of spade
                context.bezierCurveTo(
          x + width / 2, y + topHeight / 2, // control point 1
                x, y + topHeight / 2, // control point 2
                x, y // end point
              );
                
                context.closePath();
                context.fill();
                
                // bottom of spade
                context.beginPath();
                context.moveTo(x, y + topHeight);
                context.quadraticCurveTo(
          x, y + topHeight + bottomHeight, // control point
                x - bottomWidth / 2, y + topHeight + bottomHeight // end point
              );
               ...