Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: Rattrapmax6 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..
#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();
-
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.
-
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
;)
-
alleg42.dll not found...
-
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.
-
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..)
-
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.
-
Nice colour gradient :)