RGB Cube

Examples for Processing (BETA) version 116+. 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 3D.

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.

Created 16 January 2003

 
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);
}