Created
December 4, 2023 13:00
-
-
Save KrabCode/0335de613bbef231e7ec95ac6b60bf8f to your computer and use it in GitHub Desktop.
Two images drawn on top of one another where drawing to the foreground one gradually reveals the background by removing the alpha of the foreground.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PImage bg; | |
PImage fg; | |
PGraphics pg; | |
int brushRadius = 30; | |
void setup() { | |
size(800, 600, P2D); | |
smooth(2); | |
bg = loadImage("https://wallpapersmug.com/download/800x600/05bf15/galaxy-space-fantasy-art.jpg"); | |
fg = loadImage("https://images.wallpaperscraft.com/image/single/beautiful_scenery_mountains_lake_93318_800x600.jpg"); | |
pg = createGraphics(width, height, P2D); | |
pg.beginDraw(); | |
pg.image(fg, 0, 0); | |
pg.endDraw(); | |
} | |
void draw() { | |
image(bg, 0, 0); | |
image(pg, 0, 0); | |
} | |
void mousePressed() { | |
removeCircle(mouseX, mouseY, brushRadius); | |
} | |
void mouseDragged() { | |
removeLine(pmouseX, pmouseY, mouseX, mouseY, brushRadius); | |
} | |
void removeCircle(float x, float y, float radius) { | |
pg.beginDraw(); | |
pg.blendMode(REPLACE); | |
pg.fill(0, 0); | |
pg.noStroke(); | |
pg.ellipse(x, y, radius*2, radius*2); | |
pg.endDraw(); | |
} | |
void removeLine(float x0, float y0, float x1, float y1, float weight){ | |
pg.beginDraw(); | |
pg.blendMode(REPLACE); | |
pg.strokeWeight(weight*2); | |
pg.strokeCap(ROUND); | |
pg.stroke(0, 0); | |
pg.line(x0, y0, x1, y1); | |
pg.endDraw(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment