Clearing ellipse in the draw function after each frame

edited May 2016 in Kinect

I want to show an ellipse as my mouse cursos. The user can see his cursor like in photshop for drawing. When the "dikte" increases the ellipse increases size and the stroke for drawing the samen.

My problem now is that it keeps drawing the elipse when the mouse moves. Is there any way i cant erase the previous pvector?

import SimpleOpenNI.*;
SimpleOpenNI context;
PImage userImage=createImage(640,480,RGB);
PImage silhouet;
int[] userMap;
PImage rgbImage;
PGraphics pg;
PVector mouse;
color pixelColor;

int dikte = 10;
int state = 2;
int savedTime;
int totalTime = 3000;
int screenshot = 0;

void setup(){

  size(displayWidth, displayHeight);
  context=new SimpleOpenNI(this);
  context.enableRGB();
  context.enableDepth();
  context.enableUser(); 
  pg = createGraphics(displayWidth, displayHeight);
  background(255);
  silhouet = loadImage("silhouet.png");
  savedTime = millis();

  mouse = new PVector(); //PVector location

}
void draw(){
  noCursor();

  int passedTime = millis() - savedTime;

  if ( state == 0){
    background(255);

    context.update();
    rgbImage=context.rgbImage();

      userMap=context.userMap();
      userImage.loadPixels();
      userImage.resize(640, 480);
      for(int y=0;y<context.depthHeight();y++){
        for(int x=0;x<context.depthWidth();x++){
          int index=x+y*640;
          if(userMap[index]!=0){
             pixelColor=rgbImage.pixels[index];
            userImage.pixels[index]=color(0,0,0);
          }else{
            userImage.pixels[index]=color(255);
          }
        }
      }
    userImage.updatePixels();
    userImage.resize(width, height);

    image(userImage,0,0);
    textSize(50);
    fill(255, 0, 0);

    if ((3-passedTime/1000) > 0){
    text(3-(passedTime/1000),(width/2), (height/2));
    }

    if (passedTime > totalTime) {
      text("",(width/2), (height/2));
      println( " 5 seconds have passed! " );
      saveFrame("silhouet.png");
      state=1;
    }
  }

  if ( state == 1){
    mouse.set(mouseX,mouseY);
    fill(0,0,0,0);
    ellipseMode(CENTER); 
    ellipse(mouse.x,mouse.y,dikte,dikte);


    pg.beginDraw();
    pg.stroke(0);
    pg.strokeWeight(dikte);
      if (mousePressed && (mouseButton == LEFT) == true) {
        pg.stroke(0);
        pg.line(mouseX, mouseY, pmouseX, pmouseY);
      }

      if (mousePressed && (mouseButton == RIGHT) == true) {
        pg.stroke(255);
        pg.line(mouseX, mouseY, pmouseX, pmouseY);
      }
  pg.endDraw(); 
  image(pg, 0, 0);
  }

  if ( state == 2){
    textSize(32);
    fill(0, 0, 0);
    text("Press A to begin",(width/2), (height/2));
  }

  if( state > 2){
  state = 0;
  }
}

void keyPressed() {
    if (key == CODED) {
      if (keyCode == UP) {
        //Dit maakt de screenshot
        screenshot+=1;
        saveFrame("Screenshot-"+screenshot+".png");
    }
      if (keyCode == DOWN) {
        //Dit maakt de screenshot
        pg.clear();
        background(255);
        saveFrame("silhouet.png");
        savedTime = millis(); // Save the current time to restart the timer!
        state+=1;
        int dikte = 10;
    }
    if (keyCode == RIGHT && dikte<30) {
        //Dit maakt de screenshot
        dikte++;
    }
    if (keyCode == LEFT && dikte>2) {
        //Dit maakt de screenshot
        dikte--;
    }


  }
}

boolean sketchFullScreen() {
  return true;
}

The silhouet is me, the black drawing is the acual drawing as it is supposed to be. The strokes of the eclipse al need to dissapear and only the most recent mouse position needs the eclipse

Screenshot-1

Answers

  • edited June 2015 Answer ✓

    Is there any reason why you can't call background()? You did it in state 0 but not in state 1.

    You did saveFrame(), but maybe you could use pg.save() instead so it only saves the PGraphics you want instead of the whole screen?

  • Thank you, adding background(silhouet) fixed it for me.

    I want to save the frame with the drawing and the silhout form the kinect. Saving the Pgraphic would only give me the drawing i made right?

  • Yes but you could do pg.image(userImage to get the silhouette on the PGraphics.

  • Thanks i'm gone try that, i ran into a problem. Because i added background(silhout) in state 1 it recalls the previous image i made, and not the current one after the timer.

    Thanks for helping me out, i really appreciate it

  • edited June 2015

    When using pg.image(userimage,0,0) it doesn't allow me to store the new silhouet from the userimage to the pg. Instead it uses the first one it made.

    How do i solve this

    edit: pg.clear() doesn't solve it either

Sign In or Register to comment.