FAQ
 
 
Cover  \ Exhibition  \ Learning  \ Reference  \ Download  \ Discourse   
    Examples \ Tutorials \ Courses & Workshops
 
   
 
 
Examples for Processing (BETA) version 91+. 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
by REAS <http://reas.com>

The translate() function allows objects to be moved to any location within the window. The first parameter sets the x-axis offset and the second parameter sets the y-axis offset.

Created 16 January 2003

   
// Translate 
// by REAS <http://reas.com> 

float x, y; 
float size = 40.0; 
 
void setup() 
{ 
  size(200,200); 
  noStroke(); 
  framerate(30); 
} 
 
void draw() 
{ 
  background(102); 
  
  x = x + 0.8; 
  
  if (x > width + size) { 
    x = -size; 
  } 
  
  translate(x, height/2-size/2); 
  fill(255); 
  rect(-size/2, -size/2, size, size); 
  
  // Transforms add on each other. 
  // Notice how this rect moves twice 
  // as fast as the other, but it has 
  // the same parameter for the x-axis value 
  translate(x, size); 
  fill(0); 
  rect(-size/2, -size/2, size, size); 
} 
 







   
  Processing is an open project initiated by Ben Fry and Casey Reas  
  © Info