FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   blend() REVERSE
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: blend() REVERSE  (Read 604 times)
Guest
Guest
Email
blend() REVERSE
« on: Mar 2nd, 2004, 11:05pm »

Is there any way to apply a reverse effect to the fill on a rect() or triangle() function.  
Would you go about this through blend()?
 
Thank you in advance.
 
toxi

WWW
Re: blend() REVERSE
« Reply #1 on: Mar 3rd, 2004, 9:14pm »

at current, blend modes are only available for the blend() function. having them for all drawing functions would be nice, but low priority until more fundamental problems with the graphics engine have been ironed out...
 
for now, i could only come up with that brute force method...
 
Code:
BGraphics buffer;
BImage    mask;
 
void setup() {
  size(200,200);
  buffer=new BGraphics(width,height);
  framerate(2);
}
void loop() {
  // 1st draw the triangle shape
  // white on black bg
  background(0);
  fill(255);
  beginShape(TRIANGLES);
  vertex(0,0);
  vertex(200,100);
  vertex(100,200);
  endShape();
 
  // make a copy of the screen  
  mask=copy();
 
  // draw random rects into the offscreen buffer
  for(int i=0; i<100; i++) {
    buffer.fill(random(255),random(255),random(255));
    buffer.rect(random(width),random(height),random(100),random(100));
  }
 
  // now subtract the offscreen buffer from the b&w triangle image
  // because the triangle is filled white,
  // pixels in this area will be inverted
  blend(buffer,0,0,width,height,0,0,width,height,SUBSTRACT);
 
  // now invert the triangle image,
  // so that there's black triangle on white
  // this is achived by doing an binary XOR on the blue channel
  // (see alpha() in the reference guide)
  for(int i=0; i<mask.pixels.length; i++) mask.pixels[i]^=0xff;
 
  // use the inverted mask as alpha channel for the offscreen buffer
  // this basically only selects pixels outside the triangle
  buffer.alpha(mask);
 
  // blend those pixels into the main image
  blend(buffer,0,0,width,height,0,0,width,height,BLEND);
}
 

http://toxi.co.uk/
Pages: 1 

« Previous topic | Next topic »