transformist
Simple transformations in the plane. A transform in two dimensions is defined here as a translation, a rotation, and a scaling. This module lets you specify this kind of transform and apply it, or its inverse, to one or more points. Methods are also provided for composing transforms and exporting as a matrix. This is essentially wrapping mat3
transforms, but with an API that might seem friendlier. Useful for 2D games and graphics.
install
use npm
npm install transformist
examples
var transform =
var t = t> 3 4
var t = t> 0 0 -2 0
usage
t = transform(opts)
create a new transform
opts.translation
two-dimensional array in the form[x, y]
, default[0, 0]
opts.rotation
angle of rotation in degrees, default0
opts.scale
scale factor, default1
t.apply(points)
Apply transformation to one or more points
of the form [[x, y], [x, y]...]
or [x, y]
. Applies in order: scale, rotation, translation.
t.invert(points)
Undo a transformation on one or more points
of the form [[x, y], [x, y]...]
or [x, y]
. Applies the inverse transform in order: translation, rotation, scale.
t.compose(other)
Compose this transform with a transform other
, modifies in place. Equivalent to multiplying 3d transformation matrices.
t.tomat()
Return a mat3
representation of the transform.