网上看到了html版本的就试着用C再现了一下(感觉性能上不如html版本的?)
#undef UNICODE
#include<stdio.h>
#include<Windows.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
#include<math.h>
#define GRAPH_LENGTH 1600
#define GRAPH_WIDTH 900
#define VISCOSITY 15 //稠密度
typedef struct
{
int length;
int count;
}CodeRainInfo;
typedef struct
{
char ch;
int GreenVal;
}ScreenBlock;
char randchar()
{
char ch;
int a=rand() % 36;
if (a < 10)
{
ch = '0';
return ch + a;
}
else
{
ch = 'A';
return ch + a - 10;
}
}
void InitCodeRain(CodeRainInfo&r,int len)
{
r.count = 0;
r.length = rand()%(len-5)+5;
}
void InitScreenBlook(ScreenBlock**&b,int row,int rank)
{
b = (ScreenBlock**)malloc(sizeof(ScreenBlock*) * row);
for (int i = 0; i < row; i++)
b[i] = (ScreenBlock*)malloc(sizeof(ScreenBlock) * rank);
for (int i = 0; i < row; i++)
for (int j = 0; j < rank; j++)
{
b[i][j].ch = NULL;
b[i][j].GreenVal =0;
}
}
int main()
{
initgraph(GRAPH_LENGTH, GRAPH_WIDTH);
LOGFONT f;
gettextstyle(&f);
f.lfHeight = 18;
f.lfWidth = 9;
f.lfCharSet = DEFAULT_CHARSET;
settextstyle(&f);
int Row,Rank,Height,Width;//根据图框和字体大小划分的列表块
ScreenBlock** Screen;
CodeRainInfo* R;
Height = f.lfHeight;
Width = f.lfWidth;
Row = GRAPH_WIDTH /Height;
Rank= GRAPH_LENGTH /Width;
R = (CodeRainInfo*)malloc(sizeof(CodeRainInfo) * Rank);
for (int i = 0; i < Rank; i++)
InitCodeRain(R[i],Row);
InitScreenBlook(Screen,Row,Rank);
while (1)
{
for (int i = 0; i < Rank; i++)
{
Screen[R[i].count][i].ch = randchar();
Screen[R[i].count][i].GreenVal = 255;
R[i].count++;
if (R[i].count == R[i].length)InitCodeRain(R[i], Row);
}//更新
for (int i = 0; i < Row; i++)
{
for (int j = 0; j <Rank; j++)
{
if (Screen[i][j].ch != NULL)
{
settextcolor(RGB(0, Screen[i][j].GreenVal, 0));
outtextxy(j *Width, i * Height,Screen[i][j].ch);
Screen[i][j].GreenVal -= VISCOSITY;
if (Screen[i][j].GreenVal <0)
{
settextcolor(RGB(0, 0, 0));
outtextxy(j * Width, i * Height, Screen[i][j].ch);
Screen[i][j].ch = NULL;
}
}
}
}//一帧
Sleep(10); //降落速度
}
}