小程序开放平台

文档中心
基础
界面
网络
数据缓存
媒体
位置
开放接口
设备
XHSML
性能
文件
数据分析
画布
createCanvasContext
canvasPutImageData
canvasGetImageData
canvasToTempFilePath
CanvasContext
setFillStyle
setStrokeStyle
setShadow
createLinearGradient
createCircularGradient
addColorStop
setLineWidth
setLineCap
setLineJoin
setLineDash
setMiterLimit
rect
fillRect
strokeRect
clearRect
fill
stroke
beginPath
closePath
moveTo
lineTo
arc
scale
rotate
translate
setFontSize
fillText
setTextAlign
setTextBaseline
drawImage
setGlobalAlpha
measureText
strokeText
setLineDashOffset
bezierCurveTo
quadraticCurveTo
save
restore
draw
setTransform

xhs.quadraticCurveTo

开发
>
JS API
>
画布
>
CanvasContext
>
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()
    }
});

该文档是否对您有帮助?