小程序开放平台

文档中心
暂无目录

xhs.quadraticCurveTo

更新时间:2024-11-13 19:05:32

创建二次贝塞尔曲线路径。

参数

属性
类型
默认值
必填
说明
最低版本
cpxNumber贝塞尔控制点的 x 坐标
cpyNumber贝塞尔控制点的 y 坐标
xNumber结束点的 x 坐标
yNumber结束点的 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()
    }
});

该文档是否对您有帮助?