![]() |
![]() |
Examples for Processing (BETA) version 127+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.
Translate.
The third parameter to the translate() function sets the offset in the z-axis. Positive values move shapes toward the viewer and negative values move shapes away from the viewer.
float x, y;
float size = 40.0;
void setup()
{
size(200, 200, P3D);
noStroke();
}
void draw()
{
background(102);
x = x + 1.0;
if (x > width) {
x = -size;
}
translate(x, height/2-size/2, x);
fill(255);
rect(-size/2, -size/2, size, size);
translate(x, size, x/2);
fill(0);
rect(-size/2, -size/2, size, size);
}


