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.
Page Index Toggle Pages: 1
Glow (Read 1438 times)
Glow
Aug 28th, 2006, 7:13am
 
Hi,
Was just trying out a glow effect, and it works pretty well with shades of black and white.
But getting a gradient of RGB colours seems a little too complicated.
Like if I want the outer circles to have a tinge of blue, it would need a bunch of R,G and B values to colour the circles.
Anyone got a better idea for a glow that could blend in with the background colour, or at least give a torch-type glow?
Thanks!
SD :-)
Re: Glow
Reply #1 - Aug 28th, 2006, 7:14am
 
//the code that I made
int r=100,c=0,ra=70,b=255,movt=1;
void setup()
{
size(200,200);
noStroke();
background(0);
framerate(30);
//noLoop();
}
void draw()
{
background(0);
glow(100,100,ra,b);
glow(150,100,ra,b);
if (ra>=100) movt=0;
if (ra<=0) movt=1;
if (movt==1) ra=ra+3; else ra=ra-3;
}
void glow(int r,int c,int ra,int b)
{
fill(b*.0392,100);ellipse(c,r,ra,ra);
fill(b*.0784,100);ellipse(c,r,ra*.8,ra*.8);
fill(b*.1176,100);ellipse(c,r,ra*.7,ra*.7);
fill(b*.196,100);ellipse(c,r,ra*.6,ra*.6);
fill(b*.3137,100);ellipse(c,r,ra*.5,ra*.5);
fill(b*.4705,100);ellipse(c,r,ra*.4,ra*.4);
fill(b*.5882,100);ellipse(c,r,ra*.34,ra*.34);
fill(b*.7058,100);ellipse(c,r,ra*.28,ra*.28);
fill(b*.8235,100);ellipse(c,r,ra*.2,ra*.2);
fill(b*.9019,100);ellipse(c,r,ra*.14,ra*.14);
fill(b,100);ellipse(c,r,ra*.12,ra*.12);
}
Re: Glow
Reply #2 - Sep 19th, 2006, 5:10am
 
Rather than changing the color, you should just use the same color and change the alpha value. Also, once you draw the center ellipse you only have to draw the outer ellipses as lines. Something like this:

Code:

color c = color(255, 124, 0);
float rMin = 2;
float rMax = 4;
float r = rMin;
boolean grow = true;

void setup()
{
size(200,200);
framerate(30);
ellipseMode(CENTER_RADIUS);
smooth();
r = rMin;
}
void draw()
{
background(0);
stroke(c);
fill(c);
ellipse(height/2, width/2, r, r);
noFill();
for (int i = 1; i < 20; i++)
{
stroke(red(c), green(c), blue(c), 255/i);
strokeWeight(2);
ellipse(height/2, width/2, r+i, r+i);
}
if ( grow )
{
r += 8/framerate;
if ( r > rMax ) grow = false;
}
else
{
r -= 8/framerate;
if ( r < rMin ) grow = true;
}
}
Re: Glow
Reply #3 - Sep 23rd, 2006, 1:26pm
 
Thanks a zillion for that example. Smiley
What I also found out, is that if you want a good glow effect with transparency, you can create a tiny glow image in photoshop. Then use that image in the function given below.
This way, the alpha values of the pixels are adjusted according to its brightness. So the darkest pixels become most transparent and vice versa.
I got this idea from the StarNursery program.
Cheers! Smiley

void brightToAlpha(PImage b)
{
  b.format = RGB;
  for(int i=0; i < b.pixels.length; i++) {
    float j=(brightness(b.pixels[i])/225)*100;
    b.pixels[i] = color(255,255,255,j);
  }
}
Page Index Toggle Pages: 1