CanvasContext.bezierCurveTo

Create cubic Bézier curve path.

Parameters

It is Object type.

PropertyTypeDescription
cp1xNumberThe x coordinate of the first point.
cp1yNumberThe y coordinate of the first point. 
cp2xNumberThe x coordinate of the second point.
cp2yNumberThe y coordinate of the second point.
xNumberThe x coordinate of the end point.
yNumberThe y coordinate of the end point.

Sample Code

copy
//.js
const ctx = my.createCanvasContext('myCanvas')

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)

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()

ctx.beginPath()
ctx.moveTo(20, 20)
ctx.bezierCurveTo(20, 100, 200, 100, 200, 20)
ctx.setStrokeStyle('black')
ctx.stroke()

ctx.draw()