Stamp tool in processing

Hi, I want to know if this idea is possible. I am trying to create a random stamping tool if I do a key press.

  1. I want to know if it’s possible to create a stamping tool based on newly created image like this.

Now, I only can stamp(copy) based on the original image. This the coding what I have.

PImage typecopy;

void setup() {
  size(500,500);
  frameRate(10);
  typecopy = loadImage("type.png");
  background(255);
  image(typecopy, 0, 0);
 }

void draw() {
 image(typecopy, 0, 0);
 
//if keypress u,j , copy part of image
 if(keyPressed==true){ 
 //for(int i = 0; i <20;i++);
 if (key=='u' || key=='U'){
 typecopy.copy(int(random(width)), int(random(height)),200, 200, int(random(width)), int(random(height)),200,200);
 loadPixels(); 
 pixels[int(random(200))] =  color(0); 
 updatePixels();
}
}
}
  1. Also, I want to know if I can make a stamp tool in circle shape.

Yes, you can.

  1. create a circular mask
PImage stamp;
PGraphics maskImage;
void setup() {
  size(512, 512);
  stamp = loadImage("https://forum.processing.org/processing-org.jpg");
  // create mask
  maskImage = createGraphics(512,512);
  maskImage.beginDraw();
  maskImage.ellipse(256, 256, 400, 400);
  maskImage.endDraw();
  // apply mask
  stamp.mask(maskImage);
}
void draw() {
  // show masked image
  image(stamp, 0, 0);
}

It looks like free rotating the stamp is also important to your “circular effect”. You can do that by translating to the center of the stamp position, rotating, and then translating back by half the stamp width/height.

void draw() {
  // show masked image
  translate(width/2,height/2);
  rotate(millis()*0.001);
  image(stamp, -stamp.width/2, -stamp.height/2);
}

…or use imageMode(CENTER) and just rotate.

I’m not sure that I understand your sampling question, but the key is to not copy the source onto itself – instead, draw the source onto the canvas, then copy part of the canvas onto the stamp. Then stamp the canvas… then copy part of the canvas onto the stamp. Then stamp the canvas… then copy part of the canvas onto the stamp. You don’t ever need to alter the source image.

2 Likes

Thank you so much!!! This is cool!!!