Skip to content

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.

tick 0
Draw0
rgb
Draw1
rgb
a
Draw2
xy
widthheight
Draw3
xy
Draw4
degrees
Draw5
xy
widthheight
Draw6
Draw7
rgb
a
Draw8
xy
widthheight
Draw Flush9
Stop10
@counter0number

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.

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.

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 88
draw rotate 0 0 angle
draw rect -20 -20 40 40
draw reset

The 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.