delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/21/14:35:59

From: ultrastar AT online DOT tietokone DOT fi (Niki Ruusunko)
To: djgpp AT delorie DOT com
Date: Fri, 21 Aug 1998 21:35:09 +0300
Subject: Star drawing function
Message-ID: <msg324974.thr-3e93679.f625b@online.tietokone.fi>
Organization: Tietokone Online
MIME-Version: 1.0

This is a function I plan to use in creating a sun bitmap in a game I'm
making.

void DrawStar(int color, int size)
        {
        int i;
        int starSize = size - (size >> 2);
        int r = getr32(color);
        int g = getg32(color);
        int b = getb32(color);
        int *c = new int[size];
        float nr = 0, ng = 0, nb = 0;
        float steps = 255 / (size - starSize);
        for(i = 0; i < size - starSize; i++)
                {
                if (r)
                        nr = r + steps + steps * i;
                if (g)
                        ng = g + steps + steps * i;
                if (b)
                        nb = b + steps + steps * i;
                c[size - i] = makecol32((int)nr, (int)ng, (int)nb);
                }
        steps = 255 / (starSize >> 1);
        for(i = 0; i <= starSize; i++)
                {
                nr = r + steps + steps * i;
                if (nr > 255)
                       nr = 255;
                ng = g + steps + steps * i;
                if (ng > 255)
                       ng = 255;
                nb = b + steps + steps * i;
                if (nb > 255)
                       nb = 255;
                c[starSize - i] = makecol32((int)nr, (int)ng, (int)nb);
                }
        for(i = size; i >= 0; i--)
                circlefill(dbuffer, 320, 240, i, c[i]);
        delete [] c;
        }

It does nice suns, but it doesn't work if the all color components (R, G
and B) are either 0 or 255. It ends up drawing a the light field around the
star in a different color (and almost solid, not gradient) and aligns the
actual star gradient too much inside, creating a band. Just compile
that(uses allegro), it is hard to explain. How can I fix it.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019