#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#pragma comment(lib,"winmm.lib")
#include<Windows.h>
#include<time.h>
#include<string>
#include <iostream>
#define MAXSTAR1 600
#define MAXSTAR 1000
#undef UNICODE
#undef _UNICODE
struct STAR
{
int x, y, step, style;
}star[MAXSTAR];
struct STAR1
{
int x, y, step, color;
}star1[MAXSTAR1];
IMAGE image;
void initStar1(int i)
{
star1[i].x = rand() % 640;
star1[i].y = rand() % 640;
star1[i].step = rand() % 5;
star1[i].color = RGB(rand() % 256, rand() % 256, rand() % 256);
}
void moveStar1(int i)
{
star1[i].y += star1[i].step;
if (star1[i].y > 640)
{
initStar1(i);
}
}
void initstar(int i)
{
star[i].x = rand() % 640;
star[i].y = rand() % 640;
star[i].step = rand() % 5;
star[i].style = rand() % 2;
}
void moveStar(int x)
{
for (int i = 0; i < MAXSTAR; ++i)
{
star[i].y += star[i].step;
if (star[i].y > 640)
{
initstar(i);
}
}
}
void drawStar()
{
for (int i = 0; i < MAXSTAR; ++i)
{
putpixel(star[i].x, star[i].y, RGB(255, 255, 255));
}
}
void initData()
{
srand((unsigned int)time(NULL));
for (int i = 0; i < MAXSTAR; ++i)
{
initstar(i);
}
for (int i = 0; i < MAXSTAR1; ++i)
{
initStar1(i);
}
}
int main()
{
initgraph(800, 600);
IMAGE image;
std::string filePath = "2.jpg";
if (loadimage(&image, filePath.c_str(), 640, 640) == NULL) {
std::cerr << "Failed to load image." << std::endl;
}
else {
putimage(0, 0, &image);
}
getch();
closegraph();
putimage(0, 0, &image);
while (1)
{
cleardevice();
putimage(0, 0, &image);
moveStar(0);
drawStar();
moveStar1(0);
Sleep(10);
}
closegraph();
return 0;
}