xaos-project / XaoS

Real-time interactive fractal zoomer
https://xaos-project.github.io/
GNU General Public License v2.0
515 stars 59 forks source link

Idea for extra palette generation mode #55

Open jblang opened 11 years ago

jblang commented 11 years ago

From rhialto....@gmail.com on February 16, 2011 16:31:37

Suggestion, not a problem:

Once upon a time I made a Mandelbrot generator for the Amiga. (So long ago that I can't find it on AmiNet any more). I included a wonderful palette generation option, called Rainbow Mode, which provided very nice gradual colour ranges. As far as I can remember and recreate from some code that I'm looking at, it worked as follows.

There are 3 colour sliders, for Red, Green and Blue (CMY could work too, I suppose). They range over the palette entries. For the red slider, the position indicates which palette entry has a maximum red component. The two palette entries next to it have a slightly lower red component, the 2 entries 1 further away even less, etc, until at some (selectable) distance, the red component is 0. (Similar for the other 2 colours).

I originally used a linear interpolation between maximum and minimum component value, but maybe a sinus or something else would work nicely too.

UAE (the Amiga Emulator) seems to crash on me right now, or I'd try to include a screen shot.

The code which calculates the palette (12 bits per colour, 4 bits per component):

STATIC ModifyColors() { ULONG newred, newgreen, newblue;

newred = ((struct PropInfo *)
    ColorTemplateGadgets[COLOR_RED].SpecialInfo)->HorizPot;
newgreen = ((struct PropInfo *)
    ColorTemplateGadgets[COLOR_GREEN].SpecialInfo)->HorizPot;
newblue = ((struct PropInfo *)
    ColorTemplateGadgets[COLOR_BLUE].SpecialInfo)->HorizPot;

if (RainbowMode) {
    USHORT NewPalette[MAXCOL];
    SHORT i;
    SHORT distance;

    for (i=0; i<MAXCOL; i++)    NewPalette[i] = 0;
    NewPalette[0] = GetRGB4(vp->ColorMap, 0L);
    RainbowRMax = (newred * MaxColor + ONE_HALF) >> 16;
    RainbowGMax = (newgreen * MaxColor + ONE_HALF) >> 16;
    RainbowBMax = (newblue * MaxColor + ONE_HALF) >> 16;

    if (RainbowRMax == RRMax && RainbowGMax == RGMax && 
            RainbowBMax == RBMax) return;

    RRMax = RainbowRMax;
    RGMax = RainbowGMax;
    RBMax = RainbowBMax;

    for (distance=0; distance < RainbowDistance; distance++) {
        i = 15 - (16.0 * ((float) distance / RainbowDistance)) + 0.5;
        if (i < 0)  i = 0;

        NewPalette[1 + mod(RainbowBMax + distance, MaxColor)] |= i;
        NewPalette[1 + mod(RainbowBMax - distance, MaxColor)] |= i;
        i <<= 4;
        NewPalette[1 + mod(RainbowGMax + distance, MaxColor)] |= i;
        NewPalette[1 + mod(RainbowGMax - distance, MaxColor)] |= i;
        i <<= 4;
        NewPalette[1 + mod(RainbowRMax + distance, MaxColor)] |= i;
        NewPalette[1 + mod(RainbowRMax - distance, MaxColor)] |= i;
    }

    LoadRGB4(vp, &NewPalette[0], MaxColor + 1L);
} else { /* Normal RGB mode */
    SetRGB4(vp, (ULONG) CurrentColor, newred >> 12, newgreen >> 12,
        newblue >> 12);
}

}

Original issue: http://code.google.com/p/gnuxaos/issues/detail?id=56

jblang commented 11 years ago

From rhialto....@gmail.com on February 16, 2011 15:24:33

Well, screen shots need not be done only from emulated Amigas :-)

Attachment: pict3267a.jpg pict3268a.jpg

Rhialto commented 10 years ago

(just a note to mark my identity on this site)