A sub module to hs.canvas
which provides support for basic matrix manipulations which can be used as the values for transformation
attributes in the hs.canvas
module.
For mathematical reasons that are beyond the scope of this document, a 3x3 matrix can be used to represent a series of manipulations to be applied to the coordinates of a 2 dimensional drawing object. These manipulations can include one or more of a combination of translations, rotations, shearing and scaling. Within the 3x3 matrix, only 6 numbers are actually required, and this module represents them as the following keys in a Lua table: m11
, m12
, m21
, m22
, tX
, and tY
. For those of a mathematical bent, the 3x3 matrix used within this module can be visualized as follows:
[ m11, m12, 0 ]
[ m21, m22, 0 ]
[ tX, tY, 1 ]
This module allows you to generate the table which can represent one or more of the recognized transformations without having to understand the math behind the manipulations or specify the matrix values directly.
Many of the methods defined in this module can be used both as constructors and as methods chained to a previous method or constructor. Chaining the methods in this manner allows you to combine multiple transformations into one combined table which can then be assigned to an element in your canvas. .
For more information on the mathematics behind these, you can check the web. One site I used for reference (but there are many more which go into much more detail) can be found at http://www.cs.trinity.edu/~jhowland/cs2322/2d/2d/.
Signature | hs.canvas.matrix.identity() -> matrixObject |
---|---|
Type | Constructor |
Description |
Specifies the identity matrix. Resets all existing transformations when applied as a method to an existing matrixObject. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/canvas/libcanvas_matrix.m line 15 |
Signature | hs.canvas.matrix:append(matrix) -> matrixObject |
---|---|
Type | Method |
Description |
Appends the specified matrix transformations to the matrix and returns the new matrix. This method cannot be used as a constructor. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/canvas/libcanvas_matrix.m line 66 |
Signature | hs.canvas.matrix:invert() -> matrixObject |
---|---|
Type | Method |
Description |
Generates the mathematical inverse of the matrix. This method cannot be used as a constructor. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/canvas/libcanvas_matrix.m line 43 |
Signature | hs.canvas.matrix:prepend(matrix) -> matrixObject |
---|---|
Type | Method |
Description |
Prepends the specified matrix transformations to the matrix and returns the new matrix. This method cannot be used as a constructor. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/canvas/libcanvas_matrix.m line 91 |
Signature | hs.canvas.matrix:rotate(angle) -> matrixObject |
---|---|
Type | Method |
Description |
Applies a rotation of the specified number of degrees to the transformation matrix. This method can be used as a constructor or a method. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/canvas/libcanvas_matrix.m line 116 |
Signature | hs.canvas.matrix:scale(xFactor, [yFactor]) -> matrixObject |
---|---|
Type | Method |
Description |
Applies a scaling transformation to the matrix. This method can be used as a constructor or a method. |
Parameters |
|
Returns |
|
Source | extensions/canvas/libcanvas_matrix.m line 148 |
Signature | hs.canvas.matrix:shear(xFactor, [yFactor]) -> matrixObject |
---|---|
Type | Method |
Description |
Applies a shearing transformation to the matrix. This method can be used as a constructor or a method. |
Parameters |
|
Returns |
|
Source | extensions/canvas/libcanvas_matrix.m line 181 |
Signature | hs.canvas.matrix:translate(x, y) -> matrixObject |
---|---|
Type | Method |
Description |
Applies a translation transformation to the matrix. This method can be used as a constructor or a method. |
Parameters |
|
Returns |
|
Source | extensions/canvas/libcanvas_matrix.m line 220 |
© 2014–2017 Hammerspoon contributors
Licensed under the MIT License.
https://www.hammerspoon.org/docs/hs.canvas.matrix.html