星空特效

源代码:

#include 
#include 
#include 

#define MAXSTAR 700

class STAR {
public:
	double x;
	int y;
	double step;
	int color;
};

STAR star[MAXSTAR];

bool quilkly = false,slowly=false;

void InitStar(int i) {
	star[i].x = 0;
	star[i].y = rand() % 480;
	star[i].step = (rand() % 5000) / 1000.0 + 1;
	star[i].color = (int)(star[i].step * 255 / 6.0 + 0.5);
	star[i].color = RGB(star[i].color, star[i].color, star[i].color);
}

void MoveStar(int i) {
	putpixel((int)star[i].x, star[i].y, 0);
	quilkly?star[i].x = star[i].x+star[i].step+5: slowly? star[i].x = star[i].x + star[i].step -2 :star[i].x+= star[i].step;
	if (star[i].x > 640)
		InitStar(i);
	putpixel((int)star[i].x, star[i].y, star[i].color);
}

// 主函数
int main() {
	MOUSEMSG m;

	srand((unsigned)time(NULL));
	initgraph(640, 480);

	for (int i = 0; i < MAXSTAR; i++) 	{
		InitStar(i);
		star[i].x = rand() % 640;
	}

	while (!_kbhit()) {
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
			quilkly = !quilkly;
		if (m.uMsg == WM_RBUTTONDOWN)
			slowly = !slowly;
		for (int i = 0; i < MAXSTAR; i+=2)
			MoveStar(i);
		Sleep(20);
	}

	closegraph();
}

EXE文件:

Stars.exe

全屏版:

FullScreenStars.exe
特别卡,别用了

仅旋转版:

TurningStars.exe

README文件:

Stars

by 兄主的仙人掌

星空效果,修改自示例程序。

新增效果

  1. 左键星空快速移动,再左键取消
  2. 右键有环绕效果,再右键取消

注意:鼠标一定要不停移动,否则会卡

你可能感兴趣的:(其它,EasyX)