set-ctx
set-ctx()
An advanced element that allows you to modify the current canvas context.
Note: The transformation matrix (transform) is rounded after calling the callback function and therefore might be not exactly the matrix specified. This is due to rounding errors and should not cause any problems.
// Setting a custom transformation matrix
set-ctx(ctx => {
let mat = ((1, 0, .5, 0),
(0, 1, 0, 0),
(0, 0, 1, 0),
(0, 0, 0, 1))
ctx.transform = mat
return ctx
})
circle((z: 0), fill: red)
circle((z: 1), fill: blue)
circle((z: 2), fill: green)
You can store shared context data under a key in the ctx.shared-data
dictionary. The ctx.shared-data dictionary is not scoped by
group or scope elements and can be used for canvas global state.