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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| <!DOCTYPE html> <html>
<head> <title>绘制曲线和路径(quadraticCurveTo)</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content="图形系统开发实战:基础篇 示例"> <meta name="author" content="hjq"> <meta name="keywords" content="canvas,ladder,javascript,图形"> <script src="./js/helper.js"></script> </head>
<body style="overflow: hidden; margin:10px;"> <canvas id="canvas" width="660" height="320" style="border:solid 1px #CCCCCC; box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);"></canvas> </body> <script> let canvas = document.getElementById('canvas'); let ctx = canvas.getContext('2d'); drawGrid('lightgray', 10, 10);
ctx.beginPath(); ctx.moveTo(506, 91) ctx.bezierCurveTo(475, 91, 457, 115, 453, 140) ctx.lineTo(560, 140) ctx.bezierCurveTo(557, 116, 540, 91, 506, 91) ctx.moveTo(454, 175) ctx.bezierCurveTo(460, 202, 482, 220, 513, 220) ctx.bezierCurveTo(529, 220, 553, 214, 568, 199) ctx.lineTo(595, 230) ctx.bezierCurveTo(570, 256, 534, 263, 508, 263) ctx.bezierCurveTo(448, 263, 400, 219, 400, 157) ctx.bezierCurveTo(400, 99, 444, 50, 506, 50) ctx.bezierCurveTo(565, 50, 609, 96, 609, 157) ctx.lineTo(609, 174) ctx.lineTo(454, 174) ctx.lineTo(454, 175) ctx.closePath()
ctx.moveTo(305, 263) ctx.lineTo(305, 132) ctx.bezierCurveTo(305, 110, 294, 97, 274, 97) ctx.bezierCurveTo(255, 97, 242, 110, 234, 120) ctx.lineTo(234, 264) ctx.lineTo(180, 264) ctx.lineTo(180, 132) ctx.bezierCurveTo(180, 110, 170, 97, 149, 97) ctx.bezierCurveTo(131, 97, 118, 110, 110, 120) ctx.lineTo(110, 264) ctx.lineTo(56, 264) ctx.lineTo(56, 54) ctx.lineTo(110, 54) ctx.lineTo(110, 80) ctx.bezierCurveTo(119, 69, 140, 51, 172, 51) ctx.bezierCurveTo(201, 51, 221, 63, 229, 88) ctx.bezierCurveTo(242, 70, 264, 51, 297, 51) ctx.bezierCurveTo(336, 51, 359, 74, 359, 119) ctx.lineTo(359, 263) ctx.lineTo(304, 263) ctx.lineTo(305, 263) ctx.closePath()
ctx.lineWidth = 4; ctx.fill(); </script>
</html>
|