canvaskit-wasm 0.39 build 2026-04-29

Matrix3x3Helpers

CK.Matrix is a namespace of pure-JS helpers for building and combining 9-element 3×3 Matrix arrays. Returns plain number[]s — no allocation, no delete().

const path = new CK.Path(); path.addRect(CK.LTRBRect(-30, -30, 30, 30)); const stroke = new CK.Paint(); stroke.setStyle(CK.PaintStyle.Stroke); stroke.setStrokeWidth(2); stroke.setColor(CK.Color(40, 90, 180, 1)); stroke.setAntiAlias(true); const drawn = new CK.Path(); loop(() => { drawn.reset(); drawn.addPath(path); const angle = (mouse.x || 200) * 0.02; const m = CK.Matrix.multiply( CK.Matrix.translated(mouse.x || 200, mouse.y || 130), CK.Matrix.rotated(angle) ); drawn.transform(m); canvas.clear(CK.WHITE); canvas.drawPath(drawn, stroke); surface.flush(); });

Compose with multiply. Apply with Path.transform, Canvas.concat, etc. — anything that takes a Matrix.

Members

MemberArgsReturnsNotes
identityMatrixIdentity matrix.
invertm: MatrixMatrix | nullInverse, or null if singular.
mapPointsm: Matrix, points: number[]number[]Apply m to a flat [x0, y0, x1, y1, …] array.
multiply...matrices: Matrix[]MatrixRight-to-left multiply.
rotatedradians: number, px?: number, py?: numberMatrixRotation around (px, py) (default origin).
scaledsx: number, sy: number, px?: number, py?: numberMatrixScale around (px, py).
skewedkx: number, ky: number, px?: number, py?: numberMatrixSkew around (px, py).
translateddx: number, dy: numberMatrixTranslation matrix.

See also