Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: benny! on April 18, 2007
-
Hi.
here is a little simple explanation of the text routine used in the promo
intro for dbfinteractive ( ref. Showcase (http://dbfinteractive.com/index.php?action=tpmod;dl=item53) ).
Actually the effect is very simple - but maybe some of you want to know
how to do it in C/C++. It makes use of basic C/C++ stuff like arrays and
pointers. I added some comments in the source to make it clearer.
( Please note - I do not consider myself as a C guru. So I do not know if
everything is done stable and it its best way. If you find any bugs or have
if you have any improvements - please let me know )
//
// the basic algorithm/idea behind the text effect used
// in the dbfinteractive promo intro downloadable at :
// http://dbfinteractive.com/index.php?action=tpmod;dl=item53
//
// (c) 2oo7 by benny!weltenkonstrukteur.de
//
#include <windows.h>
#include <stdio.h>
int telexTyper ( char *pMsg, char *pTelexText ) {
// telexTyper returns 1 when message equals telexText
// else 0. It is assumed that MSG and TELEXTEXT are of
// the same length !!!
int ret = 1;
// loop the the telex text
for ( int i=0; i < strlen(pTelexText); i++ ) {
int ascii_Msg = (int)*pMsg; // get ascii value of char (scrollText)
int ascii_Tex = (int)pTelexText[i]; // get ascii value of char (telexText)
if ( ascii_Msg < ascii_Tex ){ // substract ascii value by 1
ascii_Tex--;
ret = 0;
} else if ( ascii_Msg > ascii_Tex ) { // or add ascii value by 1
ascii_Tex++;
ret = 0;
}
pTelexText[i] = (char)ascii_Tex;
pMsg++;
}
printf ( "%s\n", pTelexText );
return ret;
}
int main( ) {
// telexText holds the characters that are displayed
char telexText[7] = "AAAAA\0";
// the scroller array hold the actual text
char scroller[2][7]= { "HELLO\0",
"WORLD\0" };
// we loop as long as telexTyper return 1
// returning 1 means that the characters in the source array scroller
// are equal to the characters in the destination array telexText
while ( telexTyper ( &scroller[0][0], &telexText[0] ) == 0 );
printf ( "\nFirst scrolltext successfully displayed!\n\n" );
while ( telexTyper ( &scroller[1][0], &telexText[0] ) == 0 );
printf ( "\nSecond scrolltext successfully displayed!\n" );
// end - wait for keypress
getchar();
return 0;
}
Attached is the executable plus the source code.
-
Thanks Benny :) This is useful, especially to me mate.
-
Np. If anything is unclear and not well commented - dont hesitate to ask ;)