How do I make a stamp for this code?

Hi guys, I've been trying to figure out how to create a "stamp" whenever I click on the mouse button, but for somehow it isn't working. I still want to be able to see the circle while pressing the "stamp" on the background. Any suggestions and advice in this code? I also want to remove the printed figures in the background by just resetting the background with pressing a key.

void setup() {
  background(125);
  size(500, 500);
  smooth();
}

void draw() {
  background(125);
  stroke(255, 0, 200);
  fill(mouseY, mouseX, 200);
  ellipse(pmouseX, pmouseY, 100, 100);
}

void mousePressed() {
  background(125);
  fill(mouseX,mouseY,155);
  ellipse(mouseX,mouseY,150,150);
}

void keyPressed() {
 background(125);
}

Answers

  • edited October 2013

    You gotta create a PGraphics object to be your separate drawing layer. :P

    // forum.processing.org/two/discussion/495/how-do-i-make-a-stamp-for-this-code
    
    PGraphics bg;
    
    void setup() { 
      size(800, 600);
      frameRate(60);
      noLoop();
    
      smooth();
      noCursor();
      ellipseMode(CENTER);
    
      stroke(#FF00C0);
      strokeWeight(1.5);
    
      bg = createGraphics(width, height);
    
      bg.beginDraw();
    
      bg.smooth();
      bg.background(0200);
    
      bg.stroke(#FF00C0);
      bg.strokeWeight(2);
    
      bg.endDraw();
    }
    
    void draw() { 
      background(bg);
    
      fill(map(mouseY, 0, height, 0, 0xFF), map(mouseX, 0, width, 0, 0xFF), 0300);
      ellipse(pmouseX, pmouseY, 100, 100);
    }
    
    void keyPressed() {
      bg.background(0200);
      bg.endDraw();
    
      redraw();
    }
    
    void mousePressed() {
      bg.fill(map(mouseX, 0, width, 0, 0xFF), map(mouseY, 0, height, 0, 0xFF), 0250);
      bg.ellipse(mouseX, mouseY, 150, 150);
      bg.endDraw();
    
      redraw();
    }
    
    void mouseMoved() {
      redraw();
    }
    
    void mouseDragged() {
      redraw();
    }
    
  • Answer ✓

    When you paste code into this forum - highlight and click on the 'C' button. This will ensure that the code is formatted for others to read.

    If you want multiple 'stamps' visible at any one time you need to remember where they are an redraw them every time in draw()

    IntList cx = new IntList();
    IntList cy = new IntList();
    
    void setup() {
      size(500, 500);
      smooth();
    }
    
    void draw() {
      background(125);
      stroke(255, 0, 200);
      for (int i = 0; i < cx.size(); i++) {
        int px = cx.get(i);
        int py = cy.get(i);
    
        fill(px, py, 200);
        ellipse(px, py, 100, 100);
      }
    
      fill(mouseX, mouseY, 200);
      ellipse(mouseX, mouseY, 20, 20);
    }
    
    void mousePressed() {
      cx.append(mouseX);
      cy.append(mouseY);
    }
    
    void keyPressed() {
      background(125);
      cx.clear();
      cy.clear();
    }
    
  • Thanks a lot for the help guys!

Sign In or Register to comment.