#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
#define FONT_HEIGHT 13
#define FONT_WIDTH 11
#define MAX_DELAY 10
#define MIN_DELAY 1
#define DELAY_TIME 5000
typedef struct StringObj_tag
{
int max_delay;
int cur_delay;
int head_x;
int head_y;
int length;
char head_char;
} StringObj;
int charsInX;
int charsInY;
StringObj* ptStrObj;
void InitMatrix(void);
void Matrix(void);
void EndMatrix(void);
void InitStringObj(StringObj* obj, int i);
void DrawStringObj(StringObj* obj);
void InitGraph(void);
int main()
{
InitMatrix();
Matrix();
EndMatrix();
return 0;
}
void InitMatrix(void)
{
int i;
InitGraph();
for (i = 0; i < charsInX; i++)
InitStringObj(&ptStrObj[i], i);
}
void Matrix(void)
{
int i;
while (!kbhit())
{
for (i = 0; i < charsInX; i++)
{
if ( ptStrObj[i].head_y > charsInY + ptStrObj[i].length)
InitStringObj(&ptStrObj[i], i);
else
DrawStringObj(&ptStrObj[i]);
}
delay(DELAY_TIME);
}
}
void EndMatrix(void)
{
closegraph();
free((void*)ptStrObj);
}
void InitGraph(void)
{
int graph_mode;
int graph_driver = DETECT;
registerbgidriver(EGAVGA_driver);
initgraph(&graph_driver, &graph_mode, "");
charsInX = getmaxx()/FONT_WIDTH;
charsInY = getmaxy()/FONT_HEIGHT;
ptStrObj = (StringObj*)malloc(sizeof(StringObj)*charsInX);
}
void DrawStringObj(StringObj* obj)
{
char chs[2] = {'\0', '\0'};
int rear_x = obj->head_x * FONT_WIDTH;
int rear_y = (obj->head_y - obj->length)*FONT_HEIGHT;
int color;
if (obj->cur_delay > 0)
{
obj->cur_delay--;
return ;
}
color = ( random(2) ? LIGHTGREEN : GREEN);
setcolor(color);
chs[0] = obj->head_char;
outtextxy(obj->head_x * FONT_WIDTH, obj->head_y * FONT_HEIGHT, chs);
obj->head_y += 1;
setcolor(WHITE);
obj->head_char = chs[0] = random(0x7e - 0x21) + 0x21;
outtextxy(obj->head_x * FONT_WIDTH, obj->head_y * FONT_HEIGHT, chs);
setfillstyle(EMPTY_FILL, BLACK);
bar(rear_x, rear_y, rear_x + FONT_WIDTH - 1, rear_y + FONT_HEIGHT - 1);
obj->cur_delay = obj->max_delay;
}
void InitStringObj(StringObj* obj, int i)
{
obj->max_delay = obj->cur_delay = random(MAX_DELAY-MIN_DELAY)+MIN_DELAY;
obj->head_x = i;
obj->head_y = 0;
obj->head_char = random(0x7e-0x21) + 0x21;
obj->length = random(charsInY-10)+3;
}
源码下载:
----------------解决方案--------------------------------------------------------
挺好玩的:)
----------------解决方案--------------------------------------------------------
呵呵,不错。。
----------------解决方案--------------------------------------------------------
自己好想是个黑客了
----------------解决方案--------------------------------------------------------
好像那些电影里黑客的场景...
----------------解决方案--------------------------------------------------------
用的什么环境啊??
在TurboC/c++
Error:Udefind symbol_EGAVGA_driver in module e:\tc.c
在VC++
fatal error C1083: Cannot open include file: 'graphics.h': No such file or directory
Error executing cl.exe.
.exe文件也是黑屏.
为什么?难到我电脑不行吗???
----------------解决方案--------------------------------------------------------
可惜算法运用的是障眼法, 下落的文字是本来就预设好的背景, 运用的是颜色的遮罩效果来实现的矩阵下落
和电影里的随机的字符串的落下的效果还有一段差距啊
----------------解决方案--------------------------------------------------------
怎样把他弄成屏保啊?
----------------解决方案--------------------------------------------------------
我想把他设为屏保啊!!!有那个高手可以给个意见?
----------------解决方案--------------------------------------------------------
同问,我和6楼一样,用C-free测试也提示:'graphics.h': No such file or directory
是不是在VC和C-free里运行它,还要配置些什么?请楼主和各位高手指点下,谢谢!
----------------解决方案--------------------------------------------------------