I am trying to make a fading effect in Processing and I came up with this quick hack of sorts.
Could someone with some experience kindly tell me if this is indeed the best way of doing it or is there something better?
PGraphics pg;
void setup() {
size(320, 200);
pg = createGraphics(width, height, P2D);
smooth();
frameRate(60);
colorMode(RGB, 255, 255, 255);
pg.colorMode(RGB, 255, 255, 255);
}
void draw() {
background(0);
pg.beginDraw();
pg.tint(255, 255, 255, 200); // Make the next version of the image a little 'lighter'
pg.image(pg, 0.5, 0.5); // Put the PGraphics on top of itself (Not sure why I need 0.5 here)
pg.endDraw();
image(pg, 0, 0); // Paste the PGraphics object as an image
println(frameRate);
}
// On clicking, make an ellipse which will fade away into oblivion soon.
// The playing with colorMode is only to get aesthetically pleasing colors.
void mousePressed() {
pg.beginDraw();
pg.colorMode(HSB, 360, 100, 100);
float hue = random(360);
pg.fill(hue, 100, 100);
pg.stroke(hue, 100, 100);
pg.ellipse(mouseX, mouseY, 10, 10);
pg.colorMode(RGB, 255, 255, 255);
pg.endDraw();
}
Though this implementation works for the black background, I cannot get the transparent layer effect with it.
That is, if I place an image at the background (instead of doing a
background(0) on line 14), then the
image(pg, 0, 0) covers it with the black background. I would want the image to persist, with the fading ellipses over it.
I am guessing (after reading the preliminary 3D tutorials, which do not seem to promote the use of
camera function) that this is not the recommended way of doing things. Hence, before I blame everything from my Laptop hardware to the Java software, I would like a second opinion of how this
should be done.
One option is loading the image pixel by pixel and doing the transformations by hand; I am
hoping there is a better way?
The end result I would like is the background map of the world rotating as here:
http://vimeo.com/4587178