Use translate in WeChat applet canvas to scale the origin of coordinates


translate


Definition

Transform the origin (0, 0) of the current coordinate system. The default origin of the coordinate system is the upper left corner of the page.

Parameters

##xNumberHorizontal coordinate translation amountyNumberVertical Coordinate translation amount
ParametersTypeDescription
Example

const ctx = wx.createCanvasContext('myCanvas')

ctx.strokeRect(10, 10, 150, 100)
ctx.translate(20, 20)
ctx.strokeRect(10, 10, 150, 100)
ctx.translate(20, 20)
ctx.strokeRect(10, 10, 150, 100)

ctx.draw()

201612261753459414.png