Board index » delphi » 256 Colour Palette Generator

256 Colour Palette Generator

I'm making a fractal generator and I need some help
on making a palette "generator" in TP7. What I want
to do is to be able to input certain values like the
number of colour changes, the brightness,
percentage of red, green and blue and have it all
for either brightest to darkest or darkest to brighest.
All I need is to have the values generated and stored
in an ordinary 256 colour palette array :
Array[0..767] of Byte
or Array[0..255] of RGBattribs where RGBattribs is an Array[1..3] of Byte;

Thanks for any help possible,
Erron Silver

 

Re:256 Colour Palette Generator


There are a lot of ways to do this. One method I came up with is to create a
table of colors, then choose a random number of those (usually between 2 and
10), and also a random order that the colors will be visited in. The last
color is also set to the first color, so that the palette "wraps around"
seamlessly, ie, there's no harsh transition from the last color back to the
first.

For example, say I chose 2 colors: the first one would start at 1 (I don't
remix entry 0 so that it's always black), and the second would start at 128.
Then I would blend from color 1 to color 2, and from color 2 back to color 1.
If I chose 7 colors, there would be 7 such blendings. Each blend is roughly
255/#colors.

To blend, you have to figure out the amount of change for each component
color. Say the red level needs to go from 31 to 63 over 128 colors. 32 / 128
is 0.25, so you would add this much to the red component for each color slot.
Say green needs to go from 42 to 0 over the same range. 42 / 128 is roughly
0.34, so subtract this amount from the green component each time.

Using this method, the components and their increment values are kept as
reals, and rounded or truncated to integers when put into the array.

Another method I came up with was to set upper and lower limits for each color
component, and also choose random increment amounts. For each of the 255
colors I was going to mix, I simply added the increment, and if it was outside
the upper or lower limits, either bounce it (increment * -1), or wrap it to
the other limit. I had a method where the upper and lower limits were well
outside of the 0..63 range for component values, and if outside this internal
range, either bounced, wrapped or limited. The combination of external and
internal ranges leads to some neat combinations, the best of which is limiting
internally until it bounces externally. This gives long sequences where one
color component is at the maximum or minimum of its range, while the other two
may still be moving through the range. These tend to give the best variety of
colors.

One thing I found useful when playing with palette generation routines was to
create a program to graph the red green and blue components on top of the
colors they produced. Then you can really see what combinations lead to what
results, and get a clearer idea of how to generate them.

I also created routines to save palettes in the FractInt MAP format, and to
read such files into my programs. This really opens the door to a variety of
palette generation and usage capabilities.

Cheers, Todd
{ Todd Fiske - Portland Maine }

Other Threads