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.



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

Move the pointer left and right across the image to change its position. This program overlays one image over another by modifying the alpha value of the image.

Created 09 December 2002

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

 
PImage a, b; 
boolean once = false; 
int[] buffer; 
float bufferOffset, newBufferOffset; 
 
void setup() 
{ 
  size(200, 200); 
  buffer = new int[width*height]; 
  bufferOffset = newBufferOffset = 0.0; 
  a = loadImage("construct.jpg");  // Load an image into the program 
  b = loadImage("wash.jpg");   // Load an image into the program 
  framerate(60); 
} 
 
void draw() 
{ 
  image(a, 0, 0); 
  
  newBufferOffset = -b.width/2 + (mouseX*2-width/2); 
  float distance = bufferOffset - newBufferOffset; 
  if( abs(distance) > 0.01 ) { 
    bufferOffset -= distance/10.0; 
    bufferOffset = constrain(bufferOffset, -400, 0); 
  } 
  tint(255, 153); 
  image(b, bufferOffset, 20); 
} 
 
 
 
 
 
 







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