From: e-mail DOT address AT end DOT of DOT text (Mike Collins) Newsgroups: comp.os.msdos.djgpp Subject: Colours with Allegro Date: 23 Apr 1998 12:12:40 GMT Organization: Storage Technology Limited Lines: 93 Message-ID: <6hnb7o$prn@news.network.com> NNTP-Posting-Host: 129.80.172.119 Mime-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk /**************************************************************************** Would somebody please compile this little program and explain to me what I'm doing wrong? I want to make a coloured bar 256 pixels in length and 10 pixels high that goes : B......b.....bw.....w......W (ie, going from black to white) ... where "B" is hard black, "b" is dark grey, "w" is light grey and "W" is hard white. I make a pallete of 256 colours from R,G,B=0,0,0 to R,G,B=255,255,255 then I step through them making a bar 256 pixels long and expecting to see each x position progressively lighter than the previous, but what I get is: B.b.w.WB.b.w.WB.b.w.WB.b.w.W (with four B..W colour bars with abrupt changes from white to black between them!) The final three putpixel() lines plot the values in the pallete array, which are all the same, of course. I did this because the results made me believe I had got them wrong. If you uncomment the #define SIN, the pallete is filled as plotted on the screen. It looks like a 3-phase diagram, one phase for each colour, and I expected that it would give a bar that varied in colour smoothly and continuously along its length, but what it gives is 12 short fading bars with abrupt changes between them. What am I missing? Please help me out and I'll be in a position to help others one day! Thanks, Mike. ****************************************************************************/ #include #include #include #include //#define SIN // un-comment this line to vary colours independantly int main() { int c, x, y; double d; BITMAP *bitmap; PALLETE pallete; allegro_init(); install_keyboard(); set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); #ifdef SIN set_pallete(desktop_pallete); for (c=0; c<256; c++) { d = (PI/128); // (2 * PI / 256) pallete[c].r = (int)(128*(1+sin(c*d))); pallete[c].g = (int)(128*(1+sin((c+85)*d))); pallete[c].b = (int)(128*(1+sin((c+171)*d))); } #else for (c=0; c<256; c++) // set 256 shades of grey from black to white { pallete[c].r = c; pallete[c].g = c; pallete[c].b = c; } #endif set_pallete(pallete); y=0; for(x=0; x<256; x++) { for(y=90; y<100; y++) // make a band of colour putpixel(screen, x, y, x); putpixel(screen, x, pallete[x].r, 255); // plot the value of the colour putpixel(screen, x, pallete[x].g, 255); putpixel(screen, x, pallete[x].b, 255); } readkey(); return 0; } -- Don't just hit "reply" - my E-mail address is bogus to avoid automatic browsers from sending junk mail. Please use collim'at'anubis'dot'network'dot'com Actually, even this doesn't stop all of them ...