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

Create a three-square Bezier curve path in the WeChat small program API drawing


May 19, 2021 WeChat Mini Program Development Document


Table of contents


Create a three-square Bezier curve path in the WeChat small program API drawing Drawing interfaces and methods

canvasContext.bezierCurveTo


Defined

Create a three-square Bezier curve path.

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

Parameters

Parameters Type Description
cp1x Number The x coordinates of the first Bezier control point
cp1y Number The y coordinate of the first Bezier control point
cp2x Number The x coordinates of the second Bezier control point
cp2y Number The y coordinates of the second 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.arc(200, 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(150, 75)

ctx.moveTo(200, 20)
ctx.lineTo(200, 100)
ctx.lineTo(70, 75)
ctx.setStrokeStyle('#AAAAAA')
ctx.stroke()

// Draw quadratic curve
ctx.beginPath()
ctx.moveTo(20, 20)
ctx.bezierCurveTo(20, 100, 200, 100, 200, 20)
ctx.setStrokeStyle('black')
ctx.stroke()

ctx.draw()

Create a three-square Bezier curve path in the WeChat small program API drawing

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

  • Red: Start point (20, 20)
  • Blue: Two control points (20, 100) (200, 100)
  • Green: End point (200, 20)

Create a three-square Bezier curve path in the WeChat small program API drawing Drawing interfaces and methods