Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Create a secondary Bezier curve in the WeChat small program drawing API


May 19, 2021 WeChat Mini Program Development Document


Table of contents


Create a secondary Bezier curve in the WeChat small program drawing API Drawing interfaces and methods

canvasContext.quadraticCurveTo


Defined

Create a secondary Bezier curve path.

Tip : The starting point of the curve is the previous point in the path.

Parameters

Parameters Type Description
cpx Number The x coordinates of the Bezier control point
cpy Number The y coordinates of the Bezier control point
Number The x coordinates of the end point
Y Number The y coordinates of the end point

Example

const ctx = wx.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()

Create a secondary Bezier curve in the WeChat small program drawing API

The moveTo(20, 20) quadraticCurveTo(20, 100, 200, 20) are as follows:

  • Red: Start point (20, 20)
  • Blue: Control point (20, 100)
  • Green: End point (200, 20)

Create a secondary Bezier curve in the WeChat small program drawing API Drawing interfaces and methods