drawing with image

edited January 2018 in How To...

I want to create a program where the image is controlled by the mouse cursor so when the user clicks the image pops up in that location on the screen. The problem I am trying to fix is that the image following the mouse is continually drawing images creating a trail behind it. I can fix that problem with background(100); or drawing a rect(0,0, width, height); , however that would cover up the images purposely created by the user when he or she clicks on the screen. The idea is that the user can create images in a desired location, with the mouse cursor "carrying" that image in any location. There is an image with mouseX and mouseY coordinates, but that image need not create a trail of images behind it. So this is what I'm trying to fix. Is it possible to do this ? and can someone please give suggestions.

Answers

  • Answer ✓
    PGraphics pg;
    
    void setup(){
      size(400,400);
      pg = createGraphics(width,height);
      pg.beginDraw();
      pg.background(0);
      pg.endDraw();
    }
    
    void draw(){
      background(0);
      if(mousePressed){
        pg.beginDraw();
        pg.stroke(0,255,0);
        pg.line(mouseX,mouseY,pmouseX,pmouseY);
        pg.endDraw();
      }
      image(pg.get(),0,0);
      fill(255,0,0);
      ellipse(mouseX,mouseY,20,20);
    }
    
  • thank you it worked with my image

Sign In or Register to comment.