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 |
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Canvas</title> </head> <body> <canvas id="canvas" width="800" height="800"></canvas> <script> var ctx = canvas.getContext( "2d" ); // 获取画笔 ctx.beginPath(); ctx.lineWidth = 2; // 粗细 ctx.strokeStyle = 'rgb( 200, 200, 200 )'; // 颜色 ctx.moveTo( 100, 100 ); ctx.lineTo( 200, 200 ); ctx.lineTo( 100, 200 ); ctx.lineTo( 100, 100 ); ctx.stroke(); ctx.beginPath(); // 设置画笔属性 ctx.lineWidth = 2; // 粗细 ctx.strokeStyle = 'rgba( 255, 0, 0, 0.5 )'; // 颜色 // void quadraticCurveTo(in float cpx, in float cpy, in float x, in float y); ctx.moveTo( 100, 100 ); // 起始点 // 二次贝塞尔曲线 // 控制点 结尾点 ctx.quadraticCurveTo( 200, 200, 100, 200 ); // 渲染 ctx.stroke(); ctx.beginPath(); ctx.lineWidth = 2; // 粗细 ctx.strokeStyle = 'rgba( 255, 0, 0, 0.5 )'; // 颜色 ctx.moveTo( 400, 200 ); // 起始点 // void bezierCurveTo(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y); // 三次贝塞尔曲线 // 第一控制点 第二控制点 结束点 ctx.bezierCurveTo( 600, 200, 600, 400, 400, 400 ); ctx.stroke(); </script> </body> </html> |
测试连接