Reference+
Name
translate()
Class
PShape
Description
Specifies an amount to displace the shape. 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. Subsequent calls to the method accumulates
the effect. For example, calling translate(50, 0) and then
translate(20, 0) is the same as translate(70, 0). This
transformation is applied directly to the shape, it's not refreshed each
time draw() is run.
Using this method with the z parameter requires using the P3D
parameter in combination with size.
Examples
PShape s; void setup() { s = loadShape("bot.svg"); } void draw() { background(204); shape(s); } void mousePressed() { // Move the shape 10 pixels right each time the mouse is pressed s.translate(10, 0); }
Syntax
sh.translate(x, y)
sh.translate(x, y, z)
Parameters
sh
(PShape)
any variable of type PShapex
(float)
left/right translationy
(float)
up/down translationz
(float)
forward/back translation
Return
void
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.