We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Overall Sketch Brightness
Page Index Toggle Pages: 1
Overall Sketch Brightness (Read 640 times)
Overall Sketch Brightness
May 29th, 2009, 11:40am
 
I am looking for a method to control the brightness of all pixels on the sketch.  That is, I have already coded a "program" and am looking for a simple way to fade in and out the overall brightness of everything displayed in the sketch code.  As the code is not easily changed it would be so helpful if there is a way to control all sketch brightness values in real-time.

My first inclinations are that there is some java command to do this or maybe a way to treat my animation as an image...


Re: Overall Sketch Brightness
Reply #1 - May 29th, 2009, 2:43pm
 
May not be the best way, but you could use tint() at the end of draw().
i.e.
tint( 255*(mouseX / (float)width) );
Re: Overall Sketch Brightness
Reply #2 - May 29th, 2009, 3:11pm
 
Thanks, buddy.

I am trying the tint, but somehow the simplicity of it is lost on me. Here's code where i use a picture of black, which is in the sketch/data folder, and attempt to reveal the white background through iteration;

PImage img;
int i = 0;

void setup() {
size(400, 400);
background(255);
img = loadImage("ff.jpg");
image(img, 0, 0);
}

void draw() {
   i = (i + 1) % 255;
   tint(255, i);
   //println(i);
}
Re: Overall Sketch Brightness
Reply #3 - May 29th, 2009, 3:53pm
 
I'm not sure if I fully understand but this will fade in an image from black:
Code:
PImage img;
int i = 0;

void setup() {
size(400, 400);
background(255);
img = loadImage("wires.jpg");

}

void draw() {
i = (i + 1) % 255;
image(img, 0, 0);
tint(i);
//println(i);
}

If You mean to show the background through the picture, you will need transparency of the picture and simply change the background color.
(i.e. a black outline appears as the background becomes white)
Re: Overall Sketch Brightness
Reply #4 - May 29th, 2009, 5:18pm
 
sorry, if i misexplain, here is a better try;

i am hoping to use a layer, say a black picture, and use transparency as a means to reveal the somewhat complicated animation underneath that i have already coded.  like a fade to black in the movies.  essentially anything that will allow me to control the brightness of the entire sketch without having to rewrite all the previous code would be sweetness.  the code i posted is just a test, as the "program" i have written is too messy to post and it would be unclear what i was doing.

thanks for your patience.
Re: Overall Sketch Brightness
Reply #5 - May 29th, 2009, 5:25pm
 
also, the code you posted does not fade for me it just stays black...
Re: Overall Sketch Brightness
Reply #6 - May 29th, 2009, 7:17pm
 
Try a variation on what Noah suggested:  Just draw a black rect() over the whole screen, and adjust its opacity to reveal/hide to whatever degree you like.  So, to "fade in", start the rect() at full opacity, and decrease it slightly each frame.

You'd need to make the rect() the last thing in your draw() loop, so it draws "on top" of everything else.
Re: Overall Sketch Brightness
Reply #7 - May 30th, 2009, 11:24am
 
thanks scott, this makes sense, yet i am unable to get the rect() to change opacity, please take a look at the code;

int i = 0;

void setup() {
size(400, 400);
background(255);
}

void draw() {
   i = (i + 1) % 255;
   fill(0);
   tint(i);
   rect(0, 0, 300, 300);
   delay(10);
}
Re: Overall Sketch Brightness
Reply #8 - May 30th, 2009, 11:37am
 
nevermind, saw scott's post regarding someone else changing rect() opacity.  here it is again in case someone else is directed here;

   i = (i + 1) % 255;
   fill(255, 0, 0, i);
   rect(0, 0, 300, 300);
Re: Overall Sketch Brightness
Reply #9 - May 30th, 2009, 3:54pm
 
Yes, I recommend using fill() to change the alpha, not tint(), unless you want to affect the tint() as well.  They both can be used for alpha changes, but fill() will work better for a rect().  tint() is intended for images (pixel data).
Page Index Toggle Pages: 1