Hi there! Full disclosure, this is a part of a larger assignment for my beginner’s processing class, so if you wouldn’t mind keeping any advice fairly simple I’d really appreciate that!
Basically, I’m trying to mimic what drawing on a frosted-over window looks like (ref. image included for anyone in a warmer climate), with my problem being the snow animation in the background - it means I can’t refresh my background image, which is all I know how to do to create a paint/erase effect. Both my professor and I have tried everything we can think of, and at this point, I’d like to even know if it’s possible!
// Snow class modified from Ziv Schnieder : https://openprocessing.org/sketch/115994/
Snow[] flakes = new Snow[300];
void setup() {
size (640, 720);
// background(0);
for (int i = 0; i<flakes.length; i++) {
flakes[i] = new Snow(random(2, 10));
flakes[i].spreadY(i);
}
}
void draw() {
// BACKGROUND -------------------------------------
push();
fill(0, 0, 0, 200);
rect(0, 0, 640, 720);
pop();
// SNOWFLAKES ------------------------------------
for (int i = 0; i < flakes.length; i++) {
flakes[i] .display();
}
// WINDOW "GLASS" --------------------------------
push();
fill(255, 80);
rect(0, 0, 640, 720);
pop();
// ERASER ----------------------------------------
if (mousePressed && (mouseButton == LEFT))
{
push();
stroke(0, 90);
strokeWeight(20);
line(mouseX, mouseY, pmouseX, pmouseY);
pop();
}
// WINDOW FRAME ----------------------------------
push();
fill(0, 0, 255);
rect(0, 0, 50, 720);
rect(590, 0, 50, 720);
rect(0, 0, 640, 50);
rect(0, 670, 640, 50);
rect(300, 0, 20, 720);
rect(0, 340, 640, 20);
pop();
}
/*void mouseDragged()
{
if (mousePressed && (mouseButton == LEFT))
{
push();
stroke(0,90);
strokeWeight(20);
line(mouseX, mouseY, pmouseX, pmouseY);
pop();
}
}*/
// MISC ------------------------------------------------------------------------------------
class Snow {
float x;
float y;
float alpha;
float diameter;
float speed = random(.1, .9);
float descentX;
Snow (float tempD) {
x = random(-50, width+50);
y = random(0, 40);
diameter = tempD;
}
void spreadY(int i) {
y = y - i*3;
}
void display() {
alpha = map(y, 0, height, 255, -50);
noStroke();
fill(255, alpha);
ellipse(x, y, diameter, diameter);
y = y + speed;
x = x + descentX;
//checking the boundary
if (y > height) {
y = -diameter;
}
if (x < 0-50) {
x = width+diameter;
} else if (x > width+50) {
x = 0-diameter;
}
}
}