Color Gradients

Color Gradients

Post by Behna » Fri, 18 Jul 2003 17:12:14



I am trying to generate some nice smooth gradients that compare with
photoshop for quality and am having a bit of bother.

The way I am doing it is to generate a texture of 256 x 1 pixels (for
linear) and 256 * 256 for radial, for my purposes this resolution works
well.  I cycle through each pixel and calculate an offset 0 <= t <= 1.  I
then use this to calculate how much of each color stop to use using the code
below.  The color stops are a struct like

struct stop
{
    double offset;  // 0.0 <= offset <= 1.0
    struct
    {
        double alpha;      // 0.0 <= blue <= 1.0
        double red;       // 0.0 <= red <= 1.0
        double green;    // 0.0 <= green <= 1.0
        double blue;      // 0.0 <= blue <= 1.0
    } color;

Quote:};

This seems to be reasonably good but I don't think it's quite right.   For
example, when I have 2 stops (0.0, white) and (1.0, white) I don't get a
solid white fill.  Instead I get something that looks somewhat sinusoidal
varying from solid white at both ends with a light gray in the middle.

Does anyone have any suggestions how I can improve my code?

classColor color = new classColor(0.0, 0.0, 0.0, 0.0);
int nStops = stops.Count;
foreach (elemStop stop in stops)
{
 double deltaOffset = Math.Abs(stop.offset - t);
 double factor = (1 - deltaOffset);

 color.alpha += (factor * stop.color.alpha);

 if (factor >= 0.0)
 {
  double a = Math.Log10(1.0 / (double) nStops);
  double b = Math.Log10(deltaOffset);
  if (b != 0.0)
   factor = Math.Pow(factor,  a / b );
  else
   factor = 0;
 }
 color.red += (factor * stop.color.red);
 color.green += (factor * stop.color.green);
 color.blue += (factor * stop.color.blue);

Quote:}

Color pixColor = Color.FromArgb(color.GetAlphaByte(),  color.GetRedByte(),
color.GetGreenByte(), color.GetBlueByte());
pixelBuffer.SetPixel(x, y, pixColor);
 
 
 

1. linux: plotting-proggy for color gradients?

hello.

i am searching a programme that may
plot surfaces with colour gradients
according to acscii input like this:

x       y       z       depth
data    data    data    data

or

x       y       depth
data    data    data

the depth column should be plotted
as colour-coded. (so, i would like
to have a surface which is 'covered'
by a colour gradient.)
presumably, huge packages as maple
and such could do the job, but, please:
is there something simpler?

many thanks for your hints,
best wishes,
                marcus

********************************************************************************
Marcus Gastreich                    Tel.: ++49-228-73-5375
Lehrstuhl f.Theor.Chemie Uni Bonn   Fax.: ++49-228-73-9066

53115 Bonn, Germany                
http://www.thch.uni-bonn.de/tc/people/gastreich.marcus

2. Problem with wglCreateContext

3. ANNOUNCE: Multi-Colored Gradients

4. Can I seperate Tiffs from a PM5 file?

5. CORRECTION: ANNOUNCE: Multi-Colored Gradients

6. The Cowboy, Dodo and the Gunbot models

7. produce a color gradient in an image

8. 3d Studio adapter support

9. Single color gradient

10. Help w/color Gradient Layer in PS6

11. A colored gradient dropshadow

12. Color gradient...

13. Convert 3D function into multi-color gradient bitmap?