Search code examples
processingpixelshapessimple-openni

how to make some pixels colorless


I have a code which includes 2 layers in the display and i need to make some pixels of front layer colorless for appearance of background pixels. I couldn't find a way to make pixels invisible. In this regard I tried to create front layer by shape. the main problem with this solution is that it is so slow and cpu consuming. My code is in the following:

import processing.video.*;
import SimpleOpenNI.*;
int[] userMap;
PShape Stencil,pix;
SimpleOpenNI kinect;
 void setup(){
   size(640,480,P2D);
 kinect = new SimpleOpenNI(this);
 kinect.enableDepth();
  kinect.enableUser();
   Stencil=createShape(GROUP);
  }


  void draw(){
     background(255);
  loadPixels();
  kinect.update();
  userMap =null;
  userMap = kinect.userMap();
for (int y=0; y<480; y++) {
      for (int x=0; x<640; x++) {
        int index = x + y * 640;
        if (userMap[index] == 0) {
          pix = createShape(ELLIPSE, x, y,1,1);
  color col=color(0,0,255);
    pix.setFill(col);
  pix.setStroke(false);
 Stencil.addChild(pix);
        }
       }
    }

    shape(Stencil);
} 

would you please help me to hide or make some pixels invisible?


Solution

  • Give them a color with an alpha value. Just add a 4th parameter to any color function:

    color(0, 0, 0, 0); //transparent
    color(0, 0, 0, 128); //half transparent
    color(0, 0, 0, 255); //opaque (default)