Spill: Transformations (Symmetry, Flips, Rotation)
Rules can be transformed in various ways.
Symmetry
Apply symmetry like this:
rule()/* ... */.symmetry("Y")
rule()/* ... */.symmetry("C")
The available symmetry modes are:
Symbol | Meaning | Diagram |
---|---|---|
X | (X) axis | - |
Y | (Y) axis | | |
M | (M)ain diagonal | \ |
S | (S)kew diagonal | / |
R | order four (R)otational | |
T | order (T)wo rotational | |
C | (C)ross | + |
D | (D)iagonal cross | x |
A | (A)ll |
This function is not case sensitive.
For symmetries not in the table, you can combine multiple modes like this:
rule()/* ... */.symmetry("xs")
Flips
Flip rules like this:
rule()/* ... */.flip("x")
The flip modes use the same letters as the symmetry modes, but exist only for single axes.
Symbol | Meaning | Diagram |
---|---|---|
x | (X) axis | - |
y | (Y) axis | | |
m | (M)ain diagonal | \ |
s | (S)kew diagonal | / |
This function is not case sensitive.
Rotation
Rotate rules like this:
// these all rotate the rule clockwise 90 degrees
rule()/* ... */.rotate(1)
rule()/* ... */.rotate(-3)
rule()/* ... */.rotate(5)
The integer represents clockwise increments of 90 degrees.
Combinations
transform()
lets you access all transformations at the same time.
For symmetry, use upper case.
For flips, use lower case.
For rotation, use digits 0 to 3. (unlike rotate()
, other numbers are not supported).
// flip along the x axis, mirror the result along the main diagonal axis and rotate clockwise by 90 degrees in that order
rule()/* ... */.transform("xM1")
This function is case sensitive.
For convienience, rotations are also available in symmetry()
and flip()
rule()/* ... */.symmetry("x1")
rule()/* ... */.flip("3x")
Mininotation
Multiple transformations can also be combined using mininotation.
rule()/* ... */.transform("X,3")
There are 8 ways a shape can be flipped and rotated on a square grid.
You can use mininotation to achieve arbitrary combinations.
rule()/* ... */.transform("0,2,3,x0,x1,x3")
Identity transformation
In some cases, not transforming the rule the may also be useful.
To apply the identity transformation, use 0
.
// don't change the rule in any way
rule()/* ... */.symmetry("0")
rule()/* ... */.flip("0")
rule()/* ... */.rotate(0)
rule()/* ... */.transform("0")
Examples
To be continued.
back to the spill