Py5Shape.translate()#

Specifies an amount to displace the shape.

Examples#

 1def setup():
 2    global s
 3    s = py5.load_shape("bot.svg")
 4
 5
 6def draw():
 7    py5.background(204)
 8    py5.shape(s)
 9
10
11def mouse_pressed():
12    # move the shape 10 pixels right each time the mouse is pressed
13    s.translate(10, 0)

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.

Underlying Processing method: PShape.translate

Syntax#

translate(x: float, y: float, /) -> None
translate(x: float, y: float, z: float, /) -> None

Parameters#

  • x: float - left/right translation

  • y: float - up/down translation

  • z: float - forward/back translation

Updated on November 12, 2021 11:30:58am UTC