Quantcast
Channel: Kinect - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 530

Clearing ellipse in the draw function after each frame

$
0
0

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


Viewing all articles
Browse latest Browse all 530

Trending Articles