Files
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

64 lines
1.3 KiB
Plaintext

int r = 25;
PImage img, original, drawn;
PImage filledImage;
void setup() {
size(720, 480);
img = loadImage("coding_dragon.jpg");
original = img.get();
drawn = createImage(720, 480, RGB);
img.filter(GRAY);
}
void draw() {
image(img, 0, 0);
stroke(255, 0, 0);
noFill();
circle(mouseX, mouseY, r*2);
img.loadPixels();
original.loadPixels();
drawn.loadPixels();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++ ) {
float d = dist(mouseX, mouseY, x, y);
int randomX = constrain(x + (int)random(-2, 2), 0, width-1 );
int randomY = constrain(y + (int)random(-2, 2), 0, height-1 );
if (d <= r) {
if (mousePressed && mouseButton == LEFT) {
img.pixels[y * width + x] = original.pixels[randomY * width + randomX];
drawn.pixels[y * width + x] = color(255);
}
}
//img.set(randomX, randomY, drawn.get(x, y));
}
img.updatePixels();
drawn.updatePixels();
}
}
void mousePressed() {
if (mouseButton == RIGHT) {
filledImage = img.get();
img = drawn.get();
}
}
void mouseReleased() {
if (mouseButton == RIGHT) {
img = filledImage;
}
}
void keyPressed() {
if (keyCode == UP) {
r += 10;
} else if (keyCode == DOWN) {
r -= 10;
}
if (key == ENTER) {
setup();
}
}