Translate, rotate, scale
Easier than recomputing every point: move the grid itself and draw in it as if for the first time
A rectangle cannot be rotated by the rect command — it has no rotation field. But the grid
itself it is drawn in can be rotated.
Three squares are given identically, 40 by 40. The first is drawn as is, the second after
the grid was moved and turned, the third after a reset, back in ordinary coordinates.
Three commands and an undo
Section titled “Three commands and an undo”| Command | Fields | What it does |
|---|---|---|
translate |
x y |
moves the origin |
rotate |
angle | turns the grid by an angle in degrees |
scale |
x y |
stretches the grid along the axes |
reset |
— | puts everything back as it was |
Rotation has only one field — the angle. In the text form it still stands third:
draw rotate 0 0 90. The first two places are taken by coordinates this command does not use —
that is how every draw is written, they share one set of fields.
They accumulate: a move after a move adds up, and so does a turn after a turn. Only reset
undoes them.
What it is for
Section titled “What it is for”There is no other way to rotate a shape: rect, line and triangle have no rotation at all,
and poly has one, but only around its own centre. The grid solves both problems:
draw translate 88 88draw rotate 0 0 angledraw rect -20 -20 40 40draw resetThe square is drawn around zero — from -20 to 20 — so the rotation turns it about its
own middle, and translate puts that middle in the centre of the display. A compass needle,
a clock’s second hand, a turning turret — all of them are built this way.
Unofficial fan project, not affiliated with Anuke. Mindustry sprites, fonts and translations © Anuke, used under GPL-3.0; Fira Code under OFL-1.1. Site code is GPL-3.0.