I would do something like this.
Code:
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
HANDLE stdOut=GetStdHandle(STD_OUTPUT_HANDLE);
class CPointOnScreen
{
public:
char c;
WORD Attributes;
void Draw();
};
void CPointOnScreen::Draw()
{
SetConsoleTextAttribute(stdOut,Attributes);
cout << c << " ";
for(int j=0; j<=500; j++)
{
cout<<"";
}
}
main()
{
CPointOnScreen RowColumn[24][80]; // Assume standard 24*80 screen
CPointOnScreen *point;
int k=1;
int l=0;
int BrightLength=0;
const int COLORLENGTH=25; //length of each color change
const int COLORCHANCE=0; //chance of color change
const int COLORCHANCEMAX=12;
char Matrix[]="0123456789ABCDEF ";
srand(time(NULL));
ios::sync_with_stdio();
int row=0;
int column=0;
for(row=0;row<24;row++)
{
for(column=0;column<80;column++)
{
if(l==COLORCHANCE&&k<BrightLength) //0==how often color change happens
{
//SetConsoleTextAttribute(stdOut, FOREGROUND_GREEN|FOREGROUND_INTENSITY);
RowColumn[row][column].Attributes=FOREGROUND_GREEN|FOREGROUND_INTENSITY;
k++;
}
else if(k==BrightLength)
{
//SetConsoleTextAttribute(stdOut, FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
RowColumn[row][column].Attributes=FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY;
k=0;
}
else
{
//SetConsoleTextAttribute(stdOut, FOREGROUND_GREEN);
RowColumn[row][column].Attributes=FOREGROUND_GREEN;
BrightLength=rand()%COLORLENGTH; //25==how long color change lasts
k=0;
l=rand()%COLORCHANCEMAX; //max value that how often color change happens is compared to to find when color change happens
}
RowColumn[row][column].c=Matrix[(rand()%32)];
}
}
do
{
for(column=0;column<80;column++)
{
for(row=0;row<23;row++)
{
if( row != 23 )
RowColumn[row][column].c=RowColumn[row+1][column].c;
else
{
RowColumn[row][column].c=Matrix[(rand()%32)];
}
RowColumn[row][column].Draw();
}
}
}
while(true);
return 0;
}
The idea is, loop thru and set paramaters of each character space on the screen. Then move the characters up thru the spaces with the space maintaining its color attribute and only the character displayed changes.
Hope this helps.