Loading...
Logo
Processing Forum
curoiusbrain's Profile
30 Posts
76 Responses
0 Followers

Activity Trend

Last 30 days

Loading Chart...

Show:
Private Message
    Hi ,
    It seems nothing is wrong in  the code but somehow I am getting " java.lang.IndexOutofBoundsException Index: 0,Size: 0 " error

    Any suggestion
    error  log:
    SimpleOpenNI Version 0.27
    java.lang.RuntimeException: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
    at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:100)
    at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:205)
    at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
    at javax.media.opengl.Threading.invoke(Threading.java:191)
    at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:483)
    at processing.opengl.PGL.requestDraw(PGL.java:1149)
    at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1604)
    at processing.core.PApplet.run(PApplet.java:2176)
    at java.lang.Thread.run(Thread.java:662)
    Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at org.processing.wiki.triangulate.Triangulate.triangulate(Unknown Source)
    at user_mesh.draw(user_mesh.java:55)
    at processing.core.PApplet.handleDraw(PApplet.java:2305)
    at processing.opengl.PGL$PGLListener.display(PGL.java:2601)
    at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:588)
    at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:572)
    at javax.media.opengl.awt.GLCanvas$7.run(GLCanvas.java:1054)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1034)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:909)
    at javax.media.opengl.awt.GLCanvas$8.run(GLCanvas.java:1065)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:666)
    at java.awt.EventQueue.access$400(EventQueue.java:81)
    at java.awt.EventQueue$2.run(EventQueue.java:627)
    at java.awt.EventQueue$2.run(EventQueue.java:625)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:636)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)



    1. import SimpleOpenNI.*;
    2. import org.processing.wiki.triangulate.*;
    3. ArrayList triangles = new ArrayList();
    4. ArrayList points = new ArrayList();
    5. SimpleOpenNI  kinect;
    6. int userID;
    7. Boolean tracking=false;
    8. int[] userMap = null;
    9. void setup() {
    10.   size(640, 480, P3D);
    11.   kinect = new SimpleOpenNI(this);
    12.   kinect.enableDepth();
    13.   kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE);
    14. }

    15. void draw() {
    16.   background(0);
    17.   kinect.update();
    18.   if (kinect.getNumberOfUsers()>0) {
    19.     userMap = kinect.getUsersPixels(SimpleOpenNI.USERS_ALL);  // find out which pixels have users in them// populate  the pixels array
    20.   } // from the sketch's current contents
    21.   loadPixels();
    22.   for (int x=0; x<width; x++) {
    23.     for (int y=0; y<height; y++) {
    24.       int index = x + y * width;
    25.       if ( userMap!=null &&  userMap[index] > 0) {
    26.         points.add(new PVector(x, y));
    27.         pixels[index] = color(255, 0, 0);
    28.       }
    29.     }
    30.   }
    31.   // display the changed pixel array
    32.   updatePixels();

    33.   //-------------------------------
    34.   triangles = Triangulate.triangulate(points);
    35.   //-------------------------------
    36.   stroke(0, 40);
    37.   fill(255, 40);
    38.   beginShape(TRIANGLES);
    39.   for (int i = 0; i < triangles.size(); i++) {
    40.     Triangle t = (Triangle)triangles.get(i);
    41.     vertex(t.p1.x, t.p1.y);
    42.     vertex(t.p2.x, t.p2.y);
    43.     vertex(t.p3.x, t.p3.y);
    44.   }
    45.   endShape();
    46.   //-------------------------------
    47. }
    48. void onNewUser(int uID) {
    49.   userID = uID;
    50.   tracking = true;
    51.   println("tracking");
    52. }
    Hi,
    This code is working well in java mode but when I tried uploading it on openprocessing.org it doesn't show any thing other than background color so I tried tested it in javascript mode and but still it is not working. 

    help! I am missing anything ?


    1. int rectsize=50, up, down, right, left;
    2. Rectpush[] rect;
    3. void setup()
    4. {
    5.   size(600, 300);
    6.   rect = new Rectpush[8];
    7.   for (int i=0;i<rect.length;i++) {
    8.     float x = random(0, width-50);
    9.     float y = random(0, height-50);
    10.     rect[i] = new Rectpush(x, y, rectsize, i );
    11.   }
    12. }
    13.  
    14. void draw()
    15. {
    16.   background(#00CAFF);
    17.     noStroke();
    18.   for (int i=0;i<rect.length;i++) {
    19.     if ( rect[i].x< mouseX && mouseX < rect[i].x+rectsize && rect[i].y< mouseY && mouseY < rect[i].y+rectsize) {
    20.       fill(#FFC800);
    21.       if (right==1) rect[i].x++;
    22.       if (left==1) rect[i].x--;
    23.       if (down==1) rect[i].y++;
    24.       if (up==1) rect[i].y--;
    25.     }
    26.     else {
    27.       fill(255);
    28.     }
    29.     rect[i].update();
    30.   }
    31. }
    32. void keyPressed() {
    33.   if (key == CODED) {
    34.     if (keyCode == UP) up=1;
    35.     if (keyCode == DOWN) down=1;
    36.     if (keyCode == LEFT) left=1;
    37.     if (keyCode == RIGHT)right=1;
    38.   }
    39. }
    40.  
    41. void keyReleased()
    42. {
    43.   up=0;
    44.   down=0;
    45.   right=0;
    46.   left=0;
    47. }
    48.  
    class 


    1.  
    2. class Rectpush {
    3.   float x, y;
    4.   int rectsize;
    5.   private int i;
    6.   Rectpush(float _x, float _y, int _rectsize, int _i)
    7.   {
    8.     x = _x;
    9.     y = _y;
    10.     i = _i;
    11.     rectsize = _rectsize;
    12.   }
    13.   void update()
    14.   {
    15.     rect(x, y, rectsize, rectsize);
    16.     fill(#FF0077);
    17.     textAlign(CENTER);
    18.     text( i ,x+25,y+30);
    19.   }
    20. }
    Hi,

    I am trying to develop a Paint music application. This is how it should work, when you draw any stroke it should play the sound associated with the color and should play continuously. Every time when you make a different color stroke it should play some piece of sound. Currnelty I am only using primary colors but needed to be extend for more colors.  

    Here, I am not using any external file (any wav or mp3 but this is the idea)   and using sine wave sound generator function.  I have tried to do the same but it is not working properly   

    I also wanted to control the volume but it not happening too. 

    1. import ddf.minim.*;
    2. import ddf.minim.signals.*;
    3. //----------------------------
    4. ArrayList<Dots> poop;
    5. Minim minim;
    6. AudioOutput out;
    7. SineWave sine;
    8. //----------------------------
    9. color c;
    10. int thickness=1;
    11. float Low = 261;
    12. float High = 523; 
    13. //----------------------------
    14. void setup()
    15. {
    16.   size(500, 300);
    17.   smooth();
    18.   poop = new ArrayList();
    19.   frameRate(123);
    20.   //-------------------------
    21.   minim = new Minim(this);
    22.   out = minim.getLineOut(Minim.STEREO);// get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
    23.   //-------------------------
    24.   sine = new SineWave(440, 0.0, out.sampleRate());// create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
    25.   sine.portamento(10);// set the portamento speed on the oscillator to 200 milliseconds
    26.   out.addSignal(sine); // add the oscillator to the line out
    27.   //-------------------------
    28. }

    29. void draw()
    30. {
    31.   background(255);
    32.   
    33.   for (int k=0;k<poop.size();k++)
    34.   {
    35.     Dots dot  = (Dots) poop.get(k);
    36.     dot.display();
    37.   }
    38.   loadPixels();
    39.   for (int i=0;i<width;i++)
    40.   {
    41.     for (int j=0;j<height;j++)
    42.     { 
    43.       int index = i + j*width;
    44.       color findColor = pixels[index];
    45.       float r = red(findColor);
    46.       float g = green(findColor);
    47.       float b = blue(findColor);
    48.       if (r<255) {
    49.         color fc1 = get(i, j);
    50.         float freq1 = map(hue(fc1), 0, 255, Low, High);
    51.         sine.setFreq(freq1);
    52.         sine.setAmp(thickness/100);
    53.       }
    54.       if ( g<255) {
    55.         color fc2 = get(i, j);
    56.         float freq2 = map(hue(fc2), 0, 255, Low, High);
    57.         sine.setFreq(freq2);
    58.         sine.setAmp(thickness/100);
    59.       }
    60.       if ( b<255) {
    61.         color fc3 = get(i, j);
    62.         float freq3 = map(hue(fc3), 0, 255, Low, High);
    63.         sine.setFreq(freq3);
    64.         sine.setAmp(thickness/100);
    65.       }
    66.       else {
    67.         sine.setAmp(0.0);
    68.       }
    69.     }
    70.   }
    71. //  out.setVolume(0.5);
    72. }


    73. void keyPressed()
    74. {
    75.   if (key=='r' || key == 'R') c = color(255, 0, 0);
    76.   if (key=='g' || key == 'G') c = color(0, 255, 0);
    77.   if (key=='b' || key == 'B') c = color(0, 0, 255);
    78.   if (thickness<1) thickness=1;
    79.   if (key=='x' || key == 'X') thickness++;
    80.   if (key=='z' || key == 'Z') thickness--;
    81. }


    82. void mouseDragged()
    83. {
    84.   Dots D = new Dots(mouseX, mouseY, pmouseX, pmouseY, c, thickness);
    85.   poop.add(D);
    86. }


    87. class Dots {
    88.   int x, y, px, py;
    89.   private int thickness;
    90.   color col;
    91.   Dots(int _x, int _y, int _px, int _py, color _c, int _thickness)
    92.   {
    93.     x = _x;
    94.     y = _y;
    95.     px = _px;
    96.     py = _py;
    97.     col = _c;
    98.     thickness = _thickness;
    99.   }
    100.   void display()
    101.   {
    102.     //noStroke();
    103.     //fill(col);
    104.     strokeWeight(thickness);
    105.     stroke(col);
    106.     line(x, y, px, py);
    107.   }
    108. }
    Hi a mnon.owed, 
    I was trying to run your  Kinect Physics code .. from here
    and when I run the code I am getting this error, continuously   

    I am using Processing 2.0.1 with windows 7 on Compaq c700 machine... please help 

    java.lang.NullPointerException
    at processing.app.Library.getClassPath(Library.java:300)
    at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:422)
    at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:185)
    at processing.mode.java.JavaBuild.build(JavaBuild.java:144)
    at processing.mode.java.JavaBuild.build(JavaBuild.java:123)
    at processing.mode.java.JavaMode.handleRun(JavaMode.java:114)
    at processing.mode.java.JavaEditor$19.run(JavaEditor.java:472)
    at java.lang.Thread.run(Thread.java:662)

    Hi,

    I have wrote this code and of course it is inspired from someone's code. Here, I am facing some of these problems

    1. When I increase the speed of movements of the points, they appear as a small line parallel to line of motion.
    2. These points get connect via line if they come closer to a certain distance and it should happen like this with all the points but somewhat it is not happening.

    please tell me reason or any logic fail. I want to learn these things..... giving or fixing code help me but wont tell me the problem so please try explaining the problem.

    Thanks

    1. ArrayList poop;
    2. boolean flag=false;
    3. int distance=50;
    4. void setup()
    5. {
    6.   size(600,600);
    7.   smooth();
    8.   poop = new ArrayList();
    9.   for (int i=0;i<100;i++)
    10.   {
    11.     Particle P = new Particle();
    12.     poop.add(P);
    13.   }
    14. }
    15. void mousePressed()
    16. {
    17. }
    18. void draw()
    19. {
    20.   background(20);
    21.   for (int i=0;i<poop.size();i++)
    22.   {
    23.     Particle Pn1 = (Particle) poop.get(i);
    24.     // Pn1.display();
    25.     for (int j = i + 1; j < poop.size(); j++) {
    26.       Particle Pn2 = (Particle) poop.get(j);
    27.       Pn2.display();
    28.       if (dist(Pn1.x, Pn1.y, Pn2.x, Pn2.y)< distance)
    29.       {
    30.         for (int k = j + 1; k < poop.size(); k++) {
    31.           Particle Pn3 = (Particle) poop.get(k);
    32.           Pn3.display();
    33.           if (dist(Pn3.x, Pn3.y, Pn2.x, Pn2.y)< distance) {
    34.             if (flag) {
    35.               stroke(255, 10);
    36.               fill(Pn3.c,95); // method to access the class property
    37.             }
    38.             else {
    39.               noFill();
    40.               stroke(255, 50);
    41.             }
    42.             beginShape(TRIANGLES);
    43.             vertex(Pn1.x, Pn1.y);
    44.             vertex(Pn2.x, Pn2.y);
    45.             vertex(Pn3.x, Pn3.y);
    46.             endShape();
    47.           }
    48.         }
    49.       }
    50.     }
    51.   }
    52. }

    53. void keyPressed()
    54. {
    55.   flag=!flag;
    56. }
    57. class Particle {
    58.   float x, y;
    59.   color c;
    60.   int i=1, j=1;
    61.   Particle( )
    62.   {
    63.     x = random(0, width);
    64.     y = random(0, height);
    65.     int j = (int)random(0,4);
    66.     if(j==0)
    67.     {
    68.       c = color(#05CDE5);
    69.     }
    70.     if(j==1)
    71.     {
    72.       c = color(#FFB803);
    73.     }
    74.     if(j==2)
    75.     {
    76.       c = color(#FF035B);
    77.     }
    78.     if(j==3)
    79.     {
    80.       c = color(#3D3E3E);      
    81.     }
    82.     
    83.   }

    84.   void display()
    85.   { 
    86.     pushStyle();
    87.     strokeWeight(1);
    88.     stroke(c);
    89.     point(x, y);
    90.     popStyle();
    91.     update();
    92.   }
    93.   void update()
    94.   {
    95.     x = x + j*random(0, 0.01);
    96.     y = y + i*random(0, 0.01);
    97.     if (y > height) i=-1;
    98.     if (y < 0) i=1;
    99.     if (x > width) j=-1;
    100.     if (x < 0) j=1;
    101.   }
    102. }
    103.    
    Hi,
    Here I have written a code which should detect the size of the shape drawn on the screen and draw rectangle around it but the problem is it only saves the min value of the (x,y) coordinates of the shape and doesn't save the max value of coordinates instead it saves the last coordinates of the mouse.

    Any help ? 


    1. int flag=0;
    2. ArrayList poop;
    3. PVector PVprep, SaveMax, SaveMin;
    4. void setup()
    5. {
    6.   size(400, 400);
    7.   smooth();
    8.   poop = new ArrayList();
    9.   PVprep = new PVector(0, 0);
    10.   SaveMax = new PVector(0, 0);
    11.   SaveMin = new PVector(0, 0);
    12. }

    13. void draw()
    14. {

    15.   background(255);

    16.   for (int i=0;i<poop.size();i++)
    17.   {
    18.     PVector PV = (PVector) poop.get(i);
    19.     stroke(0);
    20.     line(PV.x, PV.y, PVprep.x, PVprep.y);
    21.     if (PV.x > SaveMax.x) 
    22.     {
    23.       SaveMax.x = PV.x;
    24.     }
    25.     if (PV.x < SaveMax.x) 
    26.     {
    27.       SaveMin.x = PV.x;
    28.     }

    29.     if (PV.y > SaveMax.y) 
    30.     {
    31.       SaveMax.y = PV.y;
    32.     }
    33.     else if (PV.y < SaveMax.y) 
    34.     {
    35.       SaveMin.y = PV.y;
    36.     }
    37.     PVprep = PV;
    38.   }

    39.   if (flag==1)
    40.   {
    41.     noFill();
    42.     stroke(255, 0, 0);
    43.     rect(SaveMin.x, SaveMin.y, abs(SaveMin.x - SaveMax.x), abs(SaveMin.y-SaveMax.y));
    44.   }
    45.   
    46.   println( "SaveMin.x " + SaveMin.x + " SaveMin.y " +  SaveMin.y + " SaveMax.x " +  SaveMax.x + " SaveMax.y " +  SaveMax.y );
    47. }

    48. void mouseDragged()
    49. {
    50.   PVector P = new PVector(mouseX, mouseY);
    51.   poop.add(P);
    52.   flag=0;
    53. }


    54. void mouseReleased()
    55. {
    56.   flag=1;
    57. }
    Hi,

    I want to add one more feature in my current drawing application. I want to draw a closed shape with mouse and paint it. Please don confuse it with filling the shape.

    Here is the image of what I need 


    Does anyone has idea how to do it ?
    Hi,
    I need help creating an erase for the this drawing application. It is a simple code and you can see that I have used PGraphics layer where I am drawing which is transparent too. So question is how to create an eraser for this transparent layer ?  

     I know I can do this other way around but  I just want it in this way.

    1. PGraphics fakeLayer;

    2. void setup()
    3. {
    4.   size(800, 400);
    5.   smooth();
    6.   fakeLayer = createGraphics(width, height);
    7. }

    8. void draw()
    9. {
    10.   background(255);
    11.   grids();

    12.   fakeLayer.beginDraw();
    13.   if(mousePressed){
    14.   fakeLayer.stroke(0);
    15.   fakeLayer.line(mouseX, mouseY, pmouseX, pmouseY);
    16.   }
    17.   fakeLayer.endDraw();
    18.   image(fakeLayer, 0, 0);
    19. }

    20. int dodge=50;

    21. void grids() {  
    22.   for (int i=0;i <width;i+=dodge) { 
    23.     for (int j=0;j<height;j+=dodge) {  
    24.       fill(0);    
    25.       textSize(8);      
    26.       text("+", i, j);
    27.     }
    28.   }
    29. }
    Hi,
    I am creating a clickable menu which I later put into an Android phone. Here, I have created 4 dummy menu and each menu has its own images and sounds ( currently sound is not there). So the problem is when I click on button '0' it clicks  button '0' zero of every menu and click until it gets the last menu. So when I click the button '0' of first menu1 it should go to the menu2 but it goes to menu4. 

    In every menu button number "10" is set to prev menu but it is also not working  and button 11 is set for MAIN MENU which is working fine. Each button will lead to some MENU so here when you click on button '0' it open another menu and if you click on  button '0' of this menu it will open some other menu and so on. 

    If you are not able to understand my problem you can simply try the application  and try clicking on the button zero.  
    I know there is some logic problem which I am not able to see so please help me to fix this. It is really urgent


    ----------------------------------------------

    P.S. I know I could have create the class of the "MENU" but I didn't do because I wanted to make it simple and understandable.  
    -----------------------------------------------

    1. //import apwidgets.*;
    2. //APMediaPlayer[] player;

    3. int flag, boxsize=200;
    4. PImage[] img1 = new PImage[12]; // LEVEL 1 IMAGES
    5. PImage[] img2 = new PImage[12]; // LEVEL 2 IMAGES
    6. PImage[] img3 = new PImage[12]; // LEVEL 3 IMAGES
    7. PImage[] img4 = new PImage[12]; // LEVEL 4 IMAGES

    8. int m1=0, m2=0, m3=0, m4=0;
    9. void setup()
    10. {
    11.   size(600, 800);
    12.   smooth();
    13.   /*/---------------AUDIO-----------------------------
    14.    for (int k=0;k<12;k++) {
    15.    player[k]= new APMediaPlayer(this);
    16.    }
    17.    //----------------LOADING AUDIO FILE--------------
    18.    for (int k=0;k<12;k++) {
    19.    player[k].setMediaFile("Greeting_5.mp3");
    20.    }*/
    21.   //----------------IMAGE  LEVEL 1--------------------------------
    22.   for (int j=0;j<12;j++) {
    23.     String str =j+".jpg";
    24.     if (str!=null) {
    25.       img1[j] = loadImage(str);
    26.       println(str);
    27.     }
    28.   }
    29.   //------------------IMAGE LEVEL 2----------------------------------
    30.   for (int j=0;j<12;j++) {
    31.     String str ="a" + j+".jpg";
    32.     if (str!=null) {
    33.       img2[j] = loadImage(str);
    34.       println(str);
    35.     }
    36.   }
    37.   //------------------IMAGE LEVEL 3----------------------------------
    38.   for (int j=0;j<12;j++) {
    39.     String str ="b" + j+".jpg";
    40.     if (str!=null) {
    41.       img3[j] = loadImage(str);
    42.       println(str);
    43.     }
    44.   }
    45.   //------------------IMAGE LEVEL 4----------------------------------
    46.   for (int j=0;j<12;j++) {
    47.     String str ="c" + j+".jpg";
    48.     if (str!=null) {
    49.       img4[j] = loadImage(str);
    50.       println(str);
    51.     }
    52.   }
    53.   //----------------------------------------------------------------
    54. }
    55. /*/---------------
    56.  public void onDestroy() {
    57.  super.onDestroy();
    58.  for (int k=0;k<12;k++) {
    59.  if (player != null) { 
    60.  player[k].release();
    61.  }
    62.  }
    63.  }
    64.  
    65.  //----------------*/

    66. void draw()
    67. {
    68.   background(#00FF4E);
    69.   pushStyle();
    70.   textMode(CENTER);
    71.   textSize(40);
    72.   text("ERROR SCREEN", width/4,height/2);
    73.   popStyle();
    74.   if (m1==0) {
    75.     menu1();
    76.   }
    77.   if (m2==1 )
    78.   {
    79.     menu2();
    80.   }
    81.   if (m3==1 )
    82.   {
    83.     menu3();
    84.   }
    85.   if (m4==1 )
    86.   {
    87.     menu4();
    88.   }
    89. }
    90. //----------------------------------------------------------------------------
    91. void menu1() {
    92.   //  if ( player[0]==null) {
    93.   //    player[1].start();
    94.   // }
    95.   for (int x = 0; x < 3 ; x++) {
    96.     for (int y=0; y<4; y++) {
    97.       int i = x + y*3;
    98.       fill(#002CFC);
    99.       stroke(0);
    100.       strokeWeight(7);
    101.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
    102.       if (img1[i]!= null) {
    103.         imageMode(CENTER);
    104.         image(img1[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2); // LEVEL 1 IMAGES
    105.       }
    106.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
    107.       {
    108.         fill(255, 0, 0, 50);
    109.         noStroke();
    110.         rect(x*boxsize, y*boxsize, boxsize, boxsize);

    111.         if (mousePressed)
    112.         {
    113.           if (i==0)
    114.           {
    115.             m1=1;
    116.             m2=1;
    117.             println("MENU 2 " + m2);
    118.           }
    119.         }
    120.       }
    121.       //textMode(CENTER);
    122.       fill(0);
    123.       textSize(24);
    124.       text(i, x*boxsize+boxsize/2, y*boxsize+3*boxsize/4+30);
    125.     }
    126.   }
    127. }
    128. //--------------MENU 2------------------------------------------------------
    129. void menu2() {
    130.   //  if ( player[0]==null) {
    131.   //    player[1].start();
    132.   // }
    133.   for (int x = 0; x < 3 ; x++) {
    134.     for (int y=0; y<4; y++) {
    135.       int i = x + y*3;
    136.       fill(#FAA700);
    137.       stroke(0);
    138.       strokeWeight(7);
    139.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
    140.       if (img2[i]!= null) {
    141.         imageMode(CENTER);
    142.         image(img2[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2);// LEVEL 2 IMAGES
    143.       }
    144.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
    145.       {
    146.         fill(255, 0, 0, 50);
    147.         noStroke();
    148.         rect(x*boxsize, y*boxsize, boxsize, boxsize);
    149.         if (mousePressed)
    150.         {
    151.           if (i==0)
    152.           {
    153.             m1=1;
    154.             m3=1;
    155.             println("GO NEXT MENU 3");
    156.           }

    157.           if (i==10 )
    158.           {
    159.             m1=1;
    160.             m2=0;
    161.             m3=0;
    162.             m4=0;
    163.             println("GO PREV MENU m1 " + m1 );
    164.           }

    165.           if (i==11 )
    166.           {
    167.             m1=0;
    168.             m2=0;
    169.             m3=0;
    170.             m4=0;
    171.             println("GO MAIN MENU m1 " + m1 );
    172.           }
    173.         }
    174.       }
    175.       //textMode(CENTER);
    176.       fill(0);
    177.       textSize(24);
    178.       text(i, x*boxsize+boxsize/2, y*boxsize+3*boxsize/4+30);
    179.       if (i==10 )
    180.       {
    181.         text("PREV MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
    182.       }
    183.       if (i==11 )
    184.       {
    185.         text("MAIN MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
    186.       }
    187.     }
    188.   }
    189. }
    190. //---------------MENU 3-----------------------------------------------------
    191. void menu3() {
    192.   //  if ( player[0]==null) {
    193.   //    player[1].start();
    194.   // }
    195.   for (int x = 0; x < 3 ; x++) {
    196.     for (int y=0; y<4; y++) {
    197.       int i = x + y*3;
    198.       fill(#00ADFA);
    199.       stroke(0);
    200.       strokeWeight(7);
    201.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
    202.       if (img3[i]!= null) {
    203.         imageMode(CENTER);
    204.         image(img3[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2); // LEVEL 3 IMAGES
    205.       }
    206.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
    207.       {
    208.         fill(255, 0, 0, 50);
    209.         noStroke();
    210.         rect(x*boxsize, y*boxsize, boxsize, boxsize);

    211.         if (mousePressed==true)
    212.         {

    213.           if (i==0)
    214.           {
    215.             m1=1;
    216.             m4=1;
    217.             println("GO NEXT MENU 4 m4 " + m4 );
    218.           }

    219.           if (i==10 )
    220.           {
    221.             m2=1;
    222.             m1=1;
    223.             m3=0;
    224.             m4=0;
    225.             println("GO PREV MENU m2 " + m2 );
    226.           }

    227.           if (i==11 )
    228.           {
    229.             m1=0;
    230.             m2=0;
    231.             m3=0;
    232.             m4=0;
    233.             println("GO MAIN MENU m1 " + m1 );
    234.           }
    235.         }
    236.       }
    237.       //textMode(CENTER);
    238.       fill(0);
    239.       textSize(24);
    240.       text(i, x*boxsize+boxsize/2, y*boxsize+3*boxsize/4+30);
    241.       if (i==10 )
    242.       {
    243.         text("PREV MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
    244.       }
    245.       if (i==11 )
    246.       {
    247.         text("MAIN MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
    248.       }
    249.     }
    250.   }
    251. }
    252. //------------------MENU 4--------------------------------------------------
    253. void menu4() {
    254.   //  if ( player[0]==null) {
    255.   //    player[1].start();
    256.   // }
    257.   for (int x = 0; x < 3 ; x++) {
    258.     for (int y=0; y<4; y++) {
    259.       int i = x + y*3;
    260.       fill(#FFF700);
    261.       stroke(0);
    262.       strokeWeight(7);
    263.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
    264.       if (img4[i]!= null) {
    265.         imageMode(CENTER);
    266.         image(img4[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2); // LEVEL 4 IMAGES
    267.       }
    268.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
    269.       {
    270.         fill(255, 0, 0, 50);
    271.         noStroke();
    272.         rect(x*boxsize, y*boxsize, boxsize, boxsize);

    273.         if (mousePressed)
    274.         {

    275.           if (i==0)
    276.           {
    277.             m1=1;
    278.             //m5=0; if I 'll add any more menu
    279.             println("GO NEXT MENU 5");
    280.           }

    281.           if (i==10 )
    282.           {
    283.             m3=1;
    284.             m1=1;
    285.             m2=0;
    286.             m4=0;
    287.             println("GO PREV MENU m3" + m3 );
    288.           }

    289.           if (i==11 )
    290.           {
    291.             m1=0;
    292.             m2=0;
    293.             m3=0;
    294.             m4=0;
    295.             println("GO MAIN MENU" );
    296.           }
    297.         }
    298.       }
    299.       //textMode(CENTER);
    300.       fill(0);
    301.       textSize(24);
    302.       text(i, x*boxsize+boxsize/2, y*boxsize+3*boxsize/4+30);
    303.       if (i==10 )
    304.       {
    305.         text("PREV MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
    306.       }
    307.       if (i==11 )
    308.       {
    309.         text("MAIN MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
    310.       }
    311.     }
    312.   }
    313. }
    APMediaPlayer doesn't seem to work with Android. I'm following a standard procedure but every time it returns the error:

    FATAL EXCEPTION: Animation Thread
    java.lang.NullPointerException
    at processing.test.screenpad2.screenpad2.setup(screenpad2.java:34)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:856)

    The same error message came when we tried Minim library as well. Kindly suggest possible solution. We are in dire need.








    1. import apwidgets.*;
    2. APMediaPlayer[] player;

    3. int flag, i, t=0, boxsize=200;
    4. PImage[] img = new PImage[12];
    5. void setup()
    6. {
    7.   size(displayWidth, displayHeight);
    8.   smooth();
    9.   //---------------AUDIO-----------------------------
    10.   for (int k=0;k<12;k++) {
    11.     player[k]= new APMediaPlayer(this);
    12.   }
    13.   //----------------LOADING AUDIO FILE--------------
    14.   for (int k=0;k<12;k++) {
    15.     player[k].setMediaFile("Greeting_5.mp3");
    16.   }
    17.   //----------------IMAGE---------------------------
    18.   for (int j=0;j<12;j++) {
    19.     String str =j+".jpg";
    20.     if (str!=null){
    21.       img[j] = loadImage(str);
    22.     println(str);
    23.   }
    24. }
    25. }
    26. //---------------
    27. public void onDestroy() {
    28.   super.onDestroy();
    29.   for (int k=0;k<12;k++) {
    30.     if (player != null) { 
    31.       player[k].release();
    32.     }
    33.   }
    34. }

    35. //----------------

    36. void draw()
    37. {
    38.   background(#00FF4E);
    39.   if (t==0)
    40.   {
    41.     menu0();
    42.     // delay(10500);
    43.   }

    44.   if (flag==0) {
    45.     menu1();
    46.   }
    47.   if (flag==1)
    48.   {
    49.     menu2();
    50.   }
    51.   if (flag==2)
    52.   {
    53.     menu3();
    54.   }
    55. }
    56. //--------------------------------------------------------------
    57. void menu0() {
    58.   player[0].start();
    59.   for (int x = 0; x < 3 ; x++) {
    60.     for (int y=0; y<4; y++) {
    61.       i = x + y*3;
    62.       fill(#FF0808);
    63.       stroke(0);
    64.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
    65.     }
    66.   }
    67. }

    68. //----------------------------------------------------------------
    69. void menu1() {
    70.   if ( player[0]==null) {
    71.     player[1].start();
    72.   }
    73.   for (int x = 0; x < 3 ; x++) {
    74.     for (int y=0; y<4; y++) {
    75.       i = x + y*3;
    76.       fill(#002CFC);
    77.       stroke(0);
    78.       strokeWeight(7);
    79.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
    80.       if (img[i]!= null) {
    81.         imageMode(CENTER);
    82.         image(img[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2);
    83.       }
    84.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
    85.       {
    86.         fill(255, 0, 0, 50);
    87.         noStroke();
    88.         rect(x*boxsize, y*boxsize, boxsize, boxsize);

    89.         if (mousePressed)
    90.         {
    91.           //println(" menu 1 " + "x = " + x + " y= " + y + " i = " + i);
    92.           if ( 0<mouseX && mouseX<boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
    93.           {
    94.             flag=1;
    95.             println("MENU 2");
    96.           }
    97.           if ( boxsize<mouseX && mouseX<2*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
    98.           {
    99.             flag=2;
    100.             println("MENU 2" );
    101.           }
    102.         }
    103.       }
    104.       //textMode(CENTER);
    105.       fill(255);
    106.       textSize(24);
    107.       text(i, x*boxsize+boxsize/2, y*boxsize+boxsize/2);
    108.       if ( i==9)
    109.       {
    110.         textSize(12);
    111.         text(" GO MENU 2", x*boxsize+boxsize/2, y*boxsize+boxsize/4);
    112.       }
    113.       if ( i==10)
    114.       {
    115.         textSize(12);
    116.         text(" GO MENU 3", x*boxsize+boxsize/2, y*boxsize+boxsize/4);
    117.       }
    118.     }
    119.   }
    120. }
    121. //--------------------------------------------------------------
    122. void menu2() {
    123.   if ( player[1]==null) {
    124.     player[2].start();
    125.   }

    126.   for (int x = 0; x < 3 ; x++) {
    127.     for (int y=0; y<4; y++) {
    128.       i = x + y*3;
    129.       fill(#FF8E03);
    130.       stroke(0);
    131.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
    132.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
    133.       {
    134.         fill(255, 0, 0, 50);
    135.         noStroke();
    136.         rect(x*boxsize, y*boxsize, boxsize, boxsize);
    137.         if (mousePressed)
    138.         {
    139.           // println(" menu 1 " + "x = " + x + " y= " + y + " i = " + i);
    140.           if ( 2*boxsize<mouseX && mouseX<3*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
    141.           {
    142.             flag=0;
    143.             println("MENU 1");
    144.           }
    145.           if ( boxsize<mouseX && mouseX<2*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
    146.           {
    147.             flag=2;
    148.             println("MENU 2" );
    149.           }
    150.         }
    151.       }
    152.       //textMode(CENTER);
    153.       fill(255);
    154.       textSize(24);
    155.       text(i, x*boxsize+50, y*boxsize+62);
    156.       if ( i==11)
    157.       {
    158.         textSize(12);
    159.         text(" GO MENU 1", x*boxsize+10, y*boxsize+3*boxsize/2);
    160.       }
    161.       if ( i==10)
    162.       {
    163.         textSize(12);
    164.         text(" GO MENU 3", x*boxsize+10, y*boxsize+3*boxsize/2);
    165.       }
    166.     }
    167.   }
    168. }
    169. //----------------------------------------------------------------
    170. void menu3() {
    171.    if ( player[2]==null) {
    172.     player[3].start();
    173.   }
    174.   
    175.   for (int x = 0; x < 3 ; x++) {
    176.     for (int y=0; y<4; y++) {
    177.       i = x + y*3;
    178.       fill(#03CAFF);
    179.       stroke(0);
    180.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
    181.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
    182.       {
    183.         fill(255, 0, 0, 50);
    184.         noStroke();
    185.         rect(x*boxsize, y*boxsize, boxsize, boxsize);
    186.         if (mousePressed)
    187.         {
    188.           // println(" menu 1 " + "x = " + x + " y= " + y + " i = " + i);
    189.           if ( 2*boxsize<mouseX && mouseX<3*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
    190.           {
    191.             flag=0;
    192.             println("MENU 1");
    193.           }
    194.           if ( 0<mouseX && mouseX<boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
    195.           {
    196.             flag=1;
    197.             println("MENU 2");
    198.           }
    199.         }
    200.       }
    201.       //textMode(CENTER);
    202.       fill(255);
    203.       textSize(24);
    204.       text(i, x*boxsize+50, y*boxsize+62);
    205.       if ( i==11)
    206.       {
    207.         textSize(12);
    208.         text(" GO MENU 1", x*boxsize+10, y*boxsize+3*boxsize/2);
    209.       }
    210.       if ( i==9)
    211.       {
    212.         textSize(12);
    213.         text(" GO MENU 2", x*boxsize+10, y*boxsize+3*boxsize/2);
    214.       }
    215.     }
    216.   }
    217. }
    Shape window is not working in " Processing 2"
    1. import java.awt.*;
    2. import com.sun.awt.AWTUtilities;
    3. import  java.awt.GraphicsDevice.*; // PC only
    4. import java.awt.Shape;
    5. import java.awt.AWTException;
    6. import java.awt.geom.*;

    7. int d = 500;

    8. void setup() {
    9.   size(d,d);
    10.   background(255);
    11.   Shape shape = null;
    12.   frame.removeNotify();
    13.   frame.setUndecorated(true);
    14.   shape = new Ellipse2D.Float(0,0,d,d);
    15.   AWTUtilities.setWindowShape(frame, shape);
    16. }

    17. void draw() {}


    Error:

    No library found for com.sun.awt
    java.lang.NullPointerException
    at processing.core.PApplet.handleDraw(PApplet.java:2301)
    at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
    at processing.core.PApplet.run(PApplet.java:2141)
    at java.lang.Thread.run(Thread.java:662)


    Any help ?
    Hi Everyone help me with this. 
    It should splash color on the PGraphics but it not happening. It is continuously throwing Null point exception error... it uses NITE click gesture to throw color ...please help


    1. import SimpleOpenNI.*;
      SimpleOpenNI context;

      PGraphics topLayer; 
      boolean      handsTrackFlag = false;
      PVector      handVec = new PVector();
      PVector      handVec2D  = new PVector();//just for drawing
      String       lastGesture = "";
      float        lastZ = 0;
      boolean      isPushing,wasPushing;
      float        yourClickThreshold = 20;//set this up as you see fit for your interaction

      void setup(){
        size(640,480);  
        context = new SimpleOpenNI(this);
        context.enableDepth();
        // enable hands + gesture generation
        context.enableGesture();
        context.enableHands();
        // add focus gestures  / here i do have some problems on the mac, i only recognize raiseHand ? Maybe cpu performance ?
        context.addGesture("Wave");
        context.addGesture("Click");
        context.addGesture("RaiseHand");
        topLayer = createGraphics(640, 480, g.getClass().getName());
      }

      void draw()
      {
        context.update();
        image(context.depthImage(),0,0);
        // draw the tracked hand
        if(handsTrackFlag){
          context.convertRealWorldToProjective(handVec,handVec2D);
          float diff = (handVec.z-lastZ);
          isPushing = diff < 0;
          if(diff > yourClickThreshold){
            if(!wasPushing && isPushing) fill(255,0,0);
            if(wasPushing && !isPushing) fill(0,255,0);
           splash();

          }else fill(255);
          lastZ = handVec.z;
          wasPushing = isPushing;
         ellipse(handVec2D.x,handVec2D.y,10,10);
        }
      image(topLayer,0,0);
      }


      // -----------------------------------------------------------------
      // hand events

      void onCreateHands(int handId,PVector pos,float time){
        println("onCreateHands - handId: " + handId + ", pos: " + pos + ", time:" + time);

        handsTrackFlag = true;
        handVec = pos;
      }

      void onUpdateHands(int handId,PVector pos,float time){
        //println("onUpdateHandsCb - handId: " + handId + ", pos: " + pos + ", time:" + time);
        handVec = pos;
      }

      void onDestroyHands(int handId,float time){
        println("onDestroyHandsCb - handId: " + handId + ", time:" + time);
        handsTrackFlag = false;
        context.addGesture(lastGesture);
      }

      // -----------------------------------------------------------------
      // gesture events

      void onRecognizeGesture(String strGesture, PVector idPosition, PVector endPosition){
        if(strGesture == "Click") println("onRecognizeGesture - strGesture: " + strGesture + ", idPosition: " + idPosition + ", endPosition:" + endPosition);

        lastGesture = strGesture;
        context.removeGesture(strGesture); 
        context.startTrackingHands(endPosition);
      }

      void onProgressGesture(String strGesture, PVector position,float progress){
        //println("onProgressGesture - strGesture: " + strGesture + ", position: " + position + ", progress:" + progress);
      }

      //---------------------------------------------------------------------------
      void splash(){
        stroke(255, 0, 0);
        fill(random(0,255),random(0,255),random(0,255));
        star((int)random(2, 8), mouseX-random(100), mouseY-random(100), random(100), random(100), -PI / 2.0, random(0, 1.5));
        star((int)random(2, 8), mouseX+random(200), mouseY+random(140), random(100), random(100), -PI / 2.0, random(0, 3.0));
        star((int)random(2, 8), mouseX+random(50), mouseY-random(78), random(100), random(100), -PI / 2.0, random(0, 2));
        star((int)random(2, 8), mouseX-random(120), mouseY+random(100), random(100), random(100), -PI / 2.0, random(0, 0.50));
      //  ellipse(mouseX + 50, mouseY + 50,random(40),random(40));

      }
       
      void star(int n, float cx, float cy, float r, float proportion)
      {
        star(n, cx, cy, 2.0 * r, 2.0 * r, 0.0, proportion);
       
      }
       
      void star(int n, float cx, float cy, float w, float h,  float startAngle, float proportion)
      {
        if (n > 2)
        {
          float angle = TWO_PI/ (random(2,6) *n);
          float dw; // draw width
          float dh; // draw height
           
          w = w / 2.0;
          h = h / 2.0;
           
          topLayer.beginShape();
          for (int i = 0; i < random(4, 12) * n; i++)
          {
            dw = w;
            dh = h;
            if (i % 2 == 1) // for odd vertices, use short radius
            {
              dw = w * proportion;
              dh = h * proportion;
            }
           topLayer.curveVertex(cx + dw * cos(startAngle + angle * i) + random(10),
              cy + dh * sin(startAngle + angle * i) + random(10));
          }
          topLayer.endShape(CLOSE);
           
        }

      }
       
      void deleteDrawing(){
        if(keyPressed && key == 'd'){
          setup();
        }
      }

    Hi Everyone,

    I have problem of unifying the two code into one. As I have frame-difference code and blob detection code. I am trying to make finger detection more robust using these two techniques. 

    I have thought that if I could apply the blob detection on the frame that is left after the frame-subtraction but it is not working. Can anyone of you give me some insight on my code ...Sometime I do lot of stupid things and got blind not to see them. 

    please help !

    Here is the code.

    1. import processing.video.*;
    2. import Blobscanner.*;
    3. Detector bd;

    4. int numPixels;
    5. int[] backgroundPixels;
    6. Capture video;
    7. int flag=0;
    8. int width=320, height=240;
    9. void setup() {
    10.   size(width, height, P2D); 
    11.   video = new Capture(this, width, height);
    12.   video.start();  
    13.   backgroundPixels = new int[width*height];
    14.   loadPixels();
    15. }

    16. void draw() {
    17.   if (video.available()) {
    18.     video.read();
    19.   }
    20.   video.loadPixels(); 
    21.   for (int y = 0; y < height; y++) {
    22.     for (int x =0; x < width; x++) {
    23.       numPixels = x + y*width;
    24.       color currColor = video.pixels[numPixels]; 
    25.       color bkgdColor = backgroundPixels[numPixels];
    26.       /*----------------------------------*/
    27.       int currR = (currColor >> 16) & 0xFF;
    28.       int currG = (currColor >> 8) & 0xFF;
    29.       int currB = currColor & 0xFF;
    30.       /*----------------------------------*/
    31.       int bkgdR = (bkgdColor >> 16) & 0xFF;
    32.       int bkgdG = (bkgdColor >> 8) & 0xFF;
    33.       int bkgdB = bkgdColor & 0xFF;
    34.       int diffR = abs(currR - bkgdR);
    35.       int diffG = abs(currG - bkgdG);
    36.       int diffB = abs(currB - bkgdB);
    37.       pixels[numPixels] = 0xFF000000 | (diffR << 16) | (diffG << 8) | diffB;
    38.     }
    39.   }
    40.   updatePixels(); 
    41.   if (flag==1) {
    42.     video.loadPixels();
    43.     bd.imageFindBlobs(video);
    44.     bd.loadBlobsFeatures();
    45.     bd.weightBlobs(false);  
    46.     bd.findCentroids(false, false);
    47.     stroke(255, 100, 0); 
    48.     for (int i = 0; i < bd.getBlobsNumber(); i++) {
    49.       fill(255, 0, 0);
    50.       noStroke();
    51.       ellipse(bd.getCentroidX(i), bd.getCentroidY(i), 5, 5);
    52.     }
    53.     updatePixels();
    54.   }
    55. }
    56. void keyPressed() {
    57.   video.loadPixels();
    58.   arraycopy(video.pixels, backgroundPixels);
    59.   flag=1;
    60.   video.filter(THRESHOLD);
    61.   bd = new Detector( this, 0, 0, video.width, video.height, 255 );
    62. }
    Hi Everyone,
    I am using SimpleOpenNi with processing 2.08b. I want to know how to calculate the distance between two objects ? Here in this case I want to calculate the distance between hand and a object.

    The first picture shows that depthmap of the scene



    Actually what I want to do is that if somehow I can check if I am touching any object or not. Here what I did,  I have hand coordinates ( handPosition.x, handPosition.y, handPosition.z) and from the rgb frame ( frame = kinect.rgbImage(); ) I am detecting the depth of the pixel at (handPosition.x, handPosition.y) 


    -------------------------------------------
    // I have a frame size(640,480);

    -----------------------
    int[] depthvalues = kinect.depth();
    int loc = handPosition.x + handPosition.y * 480 
    int mm = depthvalues[loc];

    -------------

    if ( abs(mm - handPosition.z ) < threshold ) 
    {
    println("You have touched an object");
    }

    ------------------


    Problems: handPosition.z gives me some 3 digit values where as mm gives me some 6 digit values. I dont understand why this is happening? 
    Somewhere I read the handPosition does not repsensts real depth coordinates. it has been converted using this fucntion " convertRealWorldToProjective "  

    void onCreateHands(int handId, PVector position, float time) {
      kinect.convertRealWorldToProjective(position, position);
      handPositions.add(position);
    }

    void onUpdateHands(int handId, PVector position, float time) {
      kinect.convertRealWorldToProjective(position, position);
      handPositions.add(position);
    }


    Hi,
     I know I ask a lot of question   but this one really irritating me . I  have googled a lot but couldn't find any solution.

    Question is

    I got a code from somewhere which can track any color picked from a video by mouse clicking and draw a ellipse filled with it. I want this is to use as tool to draw images over the video.

    like here :



    you will see video and graphics drawn over the video together 


    Code that I found is here :
    1. import processing.video.*; 
    2. Capture video; 
    3. color trackColor; 
    4. void setup() { 
    5.   size(320, 240); 
    6.   video = new Capture(this, width, height, 15); 
    7.   trackColor = color(255, 0, 0); 
    8.   smooth();
    9. void draw() { 
    10.   if (video.available()) { 
    11.     video.read();
    12.   } 
    13.   video.loadPixels(); 
    14.   image(video, 0, 0); 
    15.   float worldRecord = 500; 
    16.   int closestX = 0; 
    17.   int closestY = 0; 
    18.   for (int x = 0; x < video.width; x ++ ) { 
    19.     for (int y = 0; y < video.height; y ++ ) { 
    20.       int loc = x + y*video.width; 
    21.       color currentColor = video.pixels[loc]; 
    22.       float r1 = red(currentColor); 
    23.       float g1 = green(currentColor); 
    24.       float b1 = blue(currentColor); 
    25.       float r2 = red(trackColor); 
    26.       float g2 = green(trackColor); 
    27.       float b2 = blue(trackColor); 
    28.       float d = dist(r1, g1, b1, r2, g2, b2); 
    29.       if (d < worldRecord) { 
    30.         worldRecord = d; 
    31.         closestX = x; 
    32.         closestY = y;
    33.       }
    34.     }
    35.   }
    36.   if (worldRecord < 10) { 
    37.     // Draw a circle at the tracked pixel 
    38.     fill(trackColor); 
    39.     strokeWeight(4.0); 
    40.     stroke(0); 
    41.     ellipse(closestX, closestY, 16, 16);
    42.   }
    43. void mousePressed() { 
    44.   int loc = mouseX + mouseY*video.width; 
    45.   trackColor = video.pixels[loc];
    46. }
    Hi all,
    I have come across through the anaglyph 3D processing application on www.openprocessing.org . I'av gone through the codes of those application but didnt understand anything.

    Can anyone help me out step by step making a simple anaglyph 3d box in processing without any rotation and translation? 

    I have seen their codes where some used PGraphics some does without PGgraphics and it makes thing difficult to understand.

    please  help !!
    Hi everyone,

    I wanted to make an water balloons like the real one ( if possible) . It should be responsive I mean when you squeeze with mouse, it should change its shape and restore back after releasing it. 


    Hi Guys,

    Please help me !
    Here first time I am using minim library for audio input analysis.I don't know if it would serve my purpose at all. I am taking the stereo audio input from laptop microphones (left and right channel both). 

    what I want to do 

    I want to calculate the distance of the tap on my laptop screen and also want to detect if I have tapped on the right side or the left side of the screen. 

    Basically I am trying to make a poor's man touch screen detecting sound tap on the screen. 

    Any help will be appreciated 


    1. import ddf.minim.*;
    2. import ddf.minim.analysis.*;
    3. Minim minim;
    4. AudioInput in;

    5. void setup()
    6. {
    7.   size(512, 200);
    8.   smooth();
    9.   minim = new Minim(this);
    10.   in = minim.getLineIn(Minim.STEREO, 512);

    11. }

    12. void draw()
    13. {
    14.   background(145);
    15.   noStroke();

    16.   for (int i = 0; i < in.bufferSize() - 1; i++)
    17.   {
    18.     fill(255);
    19.     ellipse(100, 100, 50 + in.left.get(i+1)*50, 50 + in.left.get(i+1)*50);
    20.     ellipse(300, 100, 50 + in.right.get(i+1)*50, 50 + in.right.get(i+1)*50);

    21.     if (in.right.get(i)< in.left.get(i))
    22.     {
    23.       text("LEFT", 100, 150);
    24.     }
    25.     else if (in.right.get(i)> in.left.get(i)) {
    26.       text("RIGHT", 300, 150);
    27.     }
    28.     else
    29.     {
    30.       text("MIDDLE", 300, 150);
    31.     }
    32.   }
    33. }


    34. void stop()
    35. {
    36.   in.close();
    37.   minim.stop();
    38.   super.stop();
    39. }