创建二次贝塞尔曲线路径。
属性 | 类型 | 默认值 | 必填 | 说明 | 最低版本 |
---|---|---|---|---|---|
cpx | Number | 是 | 贝塞尔控制点的 x 坐标 | ||
cpy | Number | 是 | 贝塞尔控制点的 y 坐标 | ||
x | Number | 是 | 结束点的 x 坐标 | ||
y | Number | 是 | 结束点的 y 坐标 |
Page({ onLoad() { const canvasContext = xhs.createCanvasContext('myCanvas'); // Draw quadratic curve canvasContext.beginPath(); canvasContext.moveTo(20, 20); canvasContext.quadraticCurveTo(20, 100, 200, 20); canvasContext.setStrokeStyle('blue'); canvasContext.stroke(); canvasContext.draw(); } });
Page({ onReady: function () { const ctx = xhs.createCanvasContext('myCanvas') // Draw points ctx.beginPath() ctx.arc(20, 20, 2, 0, 2 * Math.PI) ctx.setFillStyle('red') ctx.fill() ctx.beginPath() ctx.arc(200, 20, 2, 0, 2 * Math.PI) ctx.setFillStyle('lightgreen') ctx.fill() ctx.beginPath() ctx.arc(20, 100, 2, 0, 2 * Math.PI) ctx.setFillStyle('blue') ctx.fill() ctx.setFillStyle('black') ctx.setFontSize(12) // Draw guides ctx.beginPath() ctx.moveTo(20, 20) ctx.lineTo(20, 100) ctx.lineTo(200, 20) ctx.setStrokeStyle('#AAAAAA') ctx.stroke() // Draw quadratic curve ctx.beginPath() ctx.moveTo(20, 20) ctx.quadraticCurveTo(20, 100, 200, 20) ctx.setStrokeStyle('black') ctx.stroke() ctx.draw() } });