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

WeChat gadget canvas uses translate to scale coordinate origin


May 19, 2021 WeChat Mini Program Development Document


Table of contents


WeChat gadget canvas uses translate to scale coordinate origin Drawing interfaces and methods

canvasContext.translate


Defined

Transforms the origin (0, 0) of the current coordinate system, with the default coordinate system origin in the upper-left corner of the page.

Parameters

Parameters Type Description
Number The horizontal coordinate translation
Y Number The amount of vertical coordinate translation

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

WeChat gadget canvas uses translate to scale coordinate origin

WeChat gadget canvas uses translate to scale coordinate origin Drawing interfaces and methods