Author Topic: Colour fading...  (Read 5728 times)

0 Members and 1 Guest are viewing this topic.

Offline Rattrapmax6

  • Atari ST
  • ***
  • Posts: 131
  • Karma: 5
  • World Wild Web Stallion
    • View Profile
Colour fading...
« on: October 17, 2006 »
Was toying with C++ the otherday, to broaden my knowlege of using graphics and what not in C++, and made a small interpolation example that fades colours across a small window..  :) .. simple, just another lil thing to kill my coders block.. enjoy..

Code: [Select]
#include <iostream>
#include <allegro.h>

int main()
{
allegro_init();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 400, 400, 0, 0);
set_window_title("Interpolation: Colours");
install_keyboard();

    // Make our values:
    int Start[3]; // Holds the Start colour RGB
    int End[3]; // Holds the End colour RGB
    int Show[3]; // Holds the INTEGER for the displayed colour
    float Rend[3]; // Holds the rendered floating point of the colour fade
    float InterPol[3]; // Holds the interpolation counter for RGB fade

    // Step the interpolation 400 times:
    InterPol[0] = 400;

    //Set our start colour:
    Start[1] = 255; Start[2] = 0; Start[3] = 0;
    //Set the end colour:
    End[1] = 255; End[2] = 255; End[3] = 0;

    //Calculate the interpolation step/counter.. Start-End colour value..
    InterPol[1] = (Start[1] - End[1]) / InterPol[0]; //RR
    InterPol[2] = (Start[2] - End[2]) / InterPol[0]; //GG
    InterPol[3] = (Start[3] - End[3]) / InterPol[0]; //BB

    //Set the render values (RGB) to the starting colour..
    Rend[1] = Start[1];
    Rend[2] = Start[2];
    Rend[3] = Start[3];

    // Loop 400 times (Window is 400 pixels long)
    for(int i = 0; i < 400; i++){
        //Pass render to the INTEGER holder for makecol(RR,GG,BB)...
        Show[1] = Rend[1];
        Show[2] = Rend[2];
        Show[3] = Rend[3];

        // Draw the faded line...
        line(screen, i, 0, i, 400, makecol(Show[1],Show[2],Show[3]));

        // Count off to interpolate the RGB valeus
        Rend[1] -= InterPol[1];
        Rend[2] -= InterPol[2];
        Rend[3] -= InterPol[3];
    }

    // Hold the screen...
while (!key[KEY_ESC]){
        rest(30);
}
allegro_exit();
}
END_OF_MAIN();
-Rattra (x.t.r.GRAPHICS)

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Colour fading...
« Reply #1 on: October 17, 2006 »
small request could you upload an exe mate as im on about 3 diffrent pcs a day and my dev c compiler is on my other comp but if not its cool ill compile it tomorow.
Challenge Trophies Won:

Offline Rattrapmax6

  • Atari ST
  • ***
  • Posts: 131
  • Karma: 5
  • World Wild Web Stallion
    • View Profile
Re: Colour fading...
« Reply #2 on: October 17, 2006 »
Sure, I thought about it before, but was too lazy.. Anyway, here is the compiled exe for those lacking a CPP compiler:
http://www.random-seed.net/xtrgraphics/myproggies/Colour_Fade_CPP.zip

 ;)
-Rattra (x.t.r.GRAPHICS)

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Colour fading...
« Reply #3 on: October 17, 2006 »
alleg42.dll not found...
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Colour fading...
« Reply #4 on: October 17, 2006 »
cheers mate  :)

very cool and correct i might give allegro a try now it looks quite tempting!

if you put alleg42.dll in google taj itll sort that out for you.
Challenge Trophies Won:

Offline Rattrapmax6

  • Atari ST
  • ***
  • Posts: 131
  • Karma: 5
  • World Wild Web Stallion
    • View Profile
Re: Colour fading...
« Reply #5 on: October 17, 2006 »
alleg42.dll not found...
:o I figured I was forgetting something.... Rough day, lemme patch the zip.....

***Rattra re-oploads new zip...

 ;D Enjoy!.... (Same link should do it..)
-Rattra (x.t.r.GRAPHICS)

Offline staticgerbil

  • Atari ST
  • ***
  • Posts: 113
  • Karma: 8
    • View Profile
Re: Colour fading...
« Reply #6 on: October 18, 2006 »
Nino:  If you're after a graphics library another one to look at is sdl.  I've played with sdl and allegro and i much prefered sdl.  Also sdl is compatible with gl so you can just chuck gl commands in there to get your 3d stuff done and  I found sdl to be quicker than allegro too.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Colour fading...
« Reply #7 on: October 18, 2006 »
Nice colour gradient :)
Shockwave ^ Codigos
Challenge Trophies Won: