Please note that I have modified the code posted above for conciseness (I hope that's ok). FYI, I had a duplicate code for SnowAngels: one for PApplet, and another for PGraphics. I realized I can just do two "layers" using two Pgraphics objects.
The Angel portion is wiped in one of the PGraphics object with transparent background
pg2.background(255, 255);
this allows pg object to be seen once pg2 object is drawn.
< PhiLho: Indeed
I noticed that the code above doesn't work properly. I'm reposting the original code, with a little cleanup:
float diam;
float x;
float y;
PGraphics pg;
void setup() {
size (1000,400);
background(255);
frameRate(60);
smooth();
pg = createGraphics(1000, 400, JAVA2D);
}
void draw() {
diam = random(20);
x = random(width);
y = random(height);
background(255);
pg.stroke(0);
pg.fill(255);
pg.beginDraw();
pg.smooth();
pg.ellipse(x,y,diam,diam);
pg.endDraw();
//drawAnAngel2(pg, 130);
image(pg, 0, 0);
drawAnAngel(this, 0);
}
void drawAnAngel2(PGraphics pa, color c){
pa.strokeWeight(5);
pa.strokeJoin(ROUND);
pa.stroke(c);
pa.fill(0);
/* an arm */
pa.pushMatrix();
pa.translate(200, 200);
float xx = map(mouseY, 0, height, 0, TWO_PI);
pa.rotate(xx);
pa.line(0, 50, 0, 0);
pa.popMatrix();
/* another arm (make these two a function!) */
pa.pushMatrix();
pa.translate(150, 200);
float xx2 = map(mouseY, 0, height, 0, TWO_PI);
pa.rotate(-xx2);
pa.line(0, 50, 0, 0);
pa.popMatrix();
}
void drawAnAngel(PApplet pa, color c){
pa.strokeWeight(5);
pa.strokeJoin(ROUND);
pa.stroke(c);
pa.fill(0);
/* an arm */
pa.pushMatrix();
pa.translate(200, 200);
float xx = map(mouseY, 0, height, 0, TWO_PI);
pa.rotate(xx);
pa.line(0, 50, 0, 0);
pa.popMatrix();
/* another arm (make these two a function!) */
pa.pushMatrix();
pa.translate(150, 200);
float xx2 = map(mouseY, 0, height, 0, TWO_PI);
pa.rotate(-xx2);
pa.line(0, 50, 0, 0);
pa.popMatrix();
}