Reference+
Name
translate()
Description
Specifies an amount to displace objects within the display window. The x parameter specifies left/right translation, the y parameter specifies up/down translation, and the z parameter specifies translations toward/away from the screen. Using this function with the z parameter requires using P3D as a parameter in combination with size as shown in the above example.
Transformations are cumulative and apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling translate(50, 0) and then translate(20, 0) is the same as translate(70, 0). If translate() is called within draw(), the transformation is reset when the loop begins again. This function can be further controlled by using pushMatrix() and popMatrix().Examples
size(400, 400); translate(120, 80); rect(0, 0, 220, 220);
// Translating in 3D requires P3D // as the parameter to size() size(400, 400, P3D); // Translate 30 across, 20 down, and // 50 back, or "away" from the screen. translate(120, 80, -200); rect(0, 0, 220, 220);
size(400, 400); rect(0, 0, 220, 220); // Draw rect at original 0,0 translate(120, 80); rect(0, 0, 220, 220); // Draw rect at new 0,0 translate(56, 56); rect(0, 0, 220, 220); // Draw rect at new 0,0
Syntax
translate(x, y)
translate(x, y, z)
Parameters
x
(float)
left/right translationy
(float)
up/down translationz
(float)
forward/backward translation
Return
void
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.