EasyX学习笔记(二、黑客帝国数据流)

EasyX学习笔记(二、黑客帝国数据流)

思路说明

main函数

1、main函数中应包括初始化,与显示有关的函数,与用户输入无关的更新,大致思路如下

void main()
{
	初始化;
	while(1)
	{
		显示;
		与用户输入无关的更新;
	}
	return;
}

startup函数

2、初始化包括画布颜色、大小、字体字号等的设置,但注意此时字体颜色与文字内容时变化的,初始化以此即可

void startup()
{
	初始化画布;
	初始化文字内容与颜色;
	其余一些初始化;
}

show函数

3、关于显示,文字和颜色都需要用二维数组储存起来,遍历显示即可

void show()
{
	for()
		for()
		{
			遍历文字二维数组;
			遍历颜色二维数组;
		}
}

updatewithoutinput函数

这一部分实现色彩的下落效果和数字的变化效果

void updatewithoutinput()
{
	int 二位数组用于暂存色彩信息
	for()
		for()
		{
			遍历色彩数组;
			首行随机产生新的色彩暂存至临时颜色数组;
			其余行色彩以此存入临时数组;
		}
	for()
		for()
		{
			遍历临时色彩数组;
			将临时色彩数组赋值于色彩数组传递出去;
		}

	//数字的更新亦是如此
}

结构

#include<...>

#define ...

int ...
char ...

void startup()
{}

void show()
{}

void updatewithoutinput()
{}

void main()
{
	startup();

	while(1)
	{
		show();
		updatewithoutinput();
	}

	return;
}

代码

要安装EasyX库

#include<graphics.h>
#include<conio.h>
#include<time.h>

#define High 666
#define Width 1080
#define char_size 22	//定义字符大小
#define num_x 49
#define num_y 30

int char_x,char_y;	//下落字符的坐标
int textcolor[num_x][num_y]={0};		//字符颜色
char text[num_x][num_y]={'0'};		//显示一组字符

void startup()
{
	initgraph(Width,High);
	setbkcolor(BLACK);
	cleardevice();	//初始化画布

	srand((unsigned)time(NULL));	//种下随机数

	int x,y;
	for(x=0;x<num_x;x++)
		for(y=0;y<num_y;y++)
		{
			textcolor[x][y]=y%255+rand()%255-400;	//生成字符颜色
			text[x][y]=(char)(rand()%26/1+65);		//产生随机字符
		}

	BeginBatchDraw();
}

void show()
{
	cleardevice();
	int x,y;

	for(x=0;x<num_x;x++)
		for(y=0;y<num_y;y++)
		{
			settextcolor(RGB(0,textcolor[x][y],0));		//设置字体颜色
			outtextxy(x*char_size,y*char_size,text[x][y]);		//输出字符
		}

	Sleep(50);

	FlushBatchDraw();
}

void updatewithoutinput()
{
	int x,y;
	int textcolor_temp[num_x][num_y]={0};
	char text_temp[num_x][num_y]={'0'};

	for(x=0;x<num_x;x++)
		for(y=0;y<num_y;y++)
		{
			if(y==0)
				textcolor_temp[x][y]=(rand())%255-5000;
			else
				textcolor_temp[x][y]=textcolor[x][y-1];
		}

	for(x=0;x<num_x;x++)
		for(y=0;y<num_y;y++)
				textcolor[x][y]=textcolor_temp[x][y];

	for(x=0;x<num_x;x++)
		for(y=0;y<num_y;y++)
				text_temp[x][y]=rand()%2/1+48;

	for(x=0;x<num_x;x++)
		for(y=0;y<num_y;y++)
				text[x][y]=text_temp[x][y];

}

int main()
{
	startup();

	while(1)
	{
		show();
		updatewithoutinput();
	}

	EndBatchDraw();
	return 0;
}

数据流

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值