1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <!DOCTYPE html> <html>
<head> <meta charset="utf-8"> <script src="http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <style media="screen"> canvas { border: 1px solid grey; } </style> </head>
<body> <canvas id="canvas" width="500" height="300">Your browser does not support canvas.</canvas>
<script> var canvas = $('#canvas').get(0); var ctx = canvas.getContext('2d');
drawEllipse(ctx, 100, 100, 80, 120); drawEllipse(ctx, 200, 200, 200, 80);
function drawEllipse(context, centerX, centerY, width, height) { context.beginPath(); context.moveTo(centerX, centerY - height / 2);
context.bezierCurveTo( centerX + width / 2, centerY - height / 2, centerX + width / 2, centerY + height / 2, centerX, centerY + height / 2 ); context.bezierCurveTo( centerX - width / 2, centerY + height / 2, centerX - width / 2, centerY - height / 2, centerX, centerY - height / 2 ); context.closePath(); context.stroke(); } </script> </body>
</html>
|