七夕送她的小礼物

本文分享了一段使用C++编程实现的流星雨代码,适合在七夕等特殊时刻为TA展示浪漫的数字艺术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

流星雨代码

#include"stdio.h"
#include"windows.h"
#include"easyx.h"
#include"graphics.h"
#include"math.h"//数学函数
#include"time.h"//时间函数
#include"conio.h"//非标准头文件 模拟键盘操作
#include"mmsystem.h"//媒体控制库文件 音乐
#pragma comment(lib,"winmm.lib")//媒体控制库文件
#define PI 3.14
//深度寻路
int map[8][8] = {
	1, 1, 1, 1, 1, 1, 1, 1,
	1, 3, 1, 0, 0, 1, 0, 1,
	1, 0, 1, 1, 1, 0, 0, 1,
	1, 0, 1, 0, 1, 0, 1, 1,
	1, 0, 0, 0, 0, 0, 1, 1,
	1, 0, 1, 0, 1, 0, 1, 1,
	1, 0, 1, 0, 1, 0, 2, 1,
	1, 1, 1, 1, 1, 1, 1, 1,
};
int len = 0;//计数
IMAGE img[5];
int k, b;//记录位置
struct positon
{
	int x;
	int y;
}pos[64];

//入栈
void push(int x,int y)
{
		pos[len].x = x;
		pos[len].y = y;
		int tmp = map[x][y];
		map[x][y] = 6;
		len++;
}
//出栈
//删除栈顶的元素
void pop()
{
	len--;
}

//初始化图片
void initImg()
{
	//sprintf()格式化写入字符串
	char str[30] = { 0 };
	for (int i = 0; i < 5; i++)
	{
		sprintf(str, "%d.gif", i);//第一个参数:字符串数组名
		loadimage(&img[i], str, 80, 80);//最后两个是图片的宽和高 如果没有那么大 就会被等比例拉伸
	}
}

void drawMap()
{
	for (int i = 0; i < 8; i++)
	{
		for (int j = 0; j < 8; j++)
		{
			switch (map[i][j])
			{
			case 1:
				putimage(j * 80, i * 80, &img[1]);
				break;
			case 0:
				putimage(j * 80, i * 80, &img[0]);//0代表
				break;
			case 6:
				putimage(j * 80, i * 80, &img[3]);
				break;
			case 9:
				putimage(j * 80, i * 80, &img[0]);
				break;
			case 2:
				putimage(j * 80, i * 80, &img[2]);//她
				break;
			case 3:
				putimage(j * 80, i * 80, &img[3]);//我
				break;
			case 7:
				putimage(j * 80, i * 80, &img[4]);//我&她
				break;
			}
		}
	}
}
void welcome()
{
	settextcolor(YELLOW);//设置字体的颜色

	//字体从0越来越大
	for (int i = 0; i < 50; i++)
	{
		//圆的参数方程 
		int x = 250 + 180 * sin(PI * 2 * i / 60);
		int y = 300 + 180 * cos(PI * 2 * i / 60);
		cleardevice();
		settextstyle(i, 0, "宋体");
		outtextxy(x, y, "七夕情人节");
		Sleep(25);
	}
	_getch();//暂停
	cleardevice();//清除屏幕
	settextstyle(20, 0, "宋体");//50代表高 0自适应宽度
	//写情诗
	outtextxy(50, 150, "我想以世纪和你在一起");
	outtextxy(50, 200, "I want to be with you in the century");
	outtextxy(50, 250, "跟你说话,真是为数不多的开心时光");
	outtextxy(50, 300, "Talking to you is really one of the few happy times");
	outtextxy(50, 350, "钟于,忠于,衷于,终于,我们在一起了很多天");
	outtextxy(50, 400, "Zhong Yu,loyal,sincere,and finally,We were together ");
	outtextxy(50, 450, "for many days");
	//很重要
	outtextxy(300, 500, "--------PengAoLin");

}
void star(int x, int y);  //画星星
void drawmoon();  //画月亮
void drawstar();  //画星空
void starflower1();  //烟花绽放1
void starflower2();  //烟花绽放2
void YanHua()
{
	int i;
	cleardevice();
	line(100, 421, 540, 421); // 画地平线
	drawstar();   //画星空
	while (!kbhit())
	{
		starflower1(); //烟花绽放函数1
		starflower2(); //烟花绽放函数2
		Sleep(10);
	}
	getch();
	closegraph();   // 关闭绘图窗口
}
void BiaoBaiShi()
{
	cleardevice();
	welcome();
	//指定的坐标输出文字
	settextcolor(BLUE);//设置字体颜色
	settextstyle(40, 0, "宋体");//设置字体的格式 40代表宽 0代表自适应宽度
	outtextxy(20, 50, "七夕情人节");//指定第一个字的输出位置
	settextstyle(30, 0, "楷体");//设置字体的格式 40代表宽 0代表自适应宽度
	settextcolor(GREEN);//设置字体颜色
	outtextxy(80, 100, "------To Zhang Xi");
	_getch();
	YanHua();
	return;
}

int main()
{
	initgraph(80 * 8, 80 * 8);
	initImg();
	drawMap();
	int x = 1, y = 1;
	push(x, y);
	while (1)
	{
		k = x, b = y;
		//0 1 2 3代表上下左右
		for (int i = 0; i < 5; i++)
		{
			switch (i)
			{
			case 0:
				x--;
				break;
			case 1:
				x++;
				break;
			case 2:
				y--;
				break;
			case 3:
				y++;
				break;
			case 4:
				//回退
				map[x][y] = 9;
				pop();
				break;
			}
			if (map[x][y] == 0)
			{
				push(x, y);
				break;
			}
			else if (x == 6 && y == 6)
			{
				map[x][y] = 7;
				for (int i = 0; i < len; i++)
				{
					drawMap();
				}
				_getch();
				BiaoBaiShi();//程序出口
			}
			else
			{
				x = pos[len - 1].x;
				y = pos[len - 1].y;
				//map[k][b] = 9;
			}
		}
		Sleep(100);
		system("cls");
		drawMap();
	}
	return 0;
}


void star(int x, int y)  //画星星函数
{
	int i, a;
	int n = 5;
	int x1[5], y1[5], x2[5], y2[5];
	setcolor(YELLOW);
	for (i = 0; i < 5; i++)
	{
		x1[i] = (int)(x + n*cos(i * 72 * PI / 180) + 1);
		y1[i] = (int)(y + n*sin(i * 72 * PI / 180) + 1);
		x2[i] = (int)(x + n / 2 * cos(i * 72 * PI / 180 + PI / 5) + 1);
		y2[i] = (int)(y + n / 2 * sin(i * 72 * PI / 180 + PI / 5) + 1);
	}
	for (i = 0; i<5; i++)
	{
		a = i + 1;
		if (a>4) a = 0;
		line(x1[i], y1[i], x2[i], y2[i]); //两点间画直线
		line(x2[i], y2[i], x1[a], y1[a]);
	}
}


void drawmoon()  //画月亮
{
	setfillcolor(WHITE);
	//fillcircle(550,80,40);//画圆(有边框)
	solidcircle(550, 80, 40);//画圆(无边框)
}


void drawstar()  //画星空
{
	int a[] = { 40, 250, 140, 140, 90, 350, 300 };
	int b[] = { 40, 25, 99, 100, 98, 60, 78 }, i;
	//setfillstyle(1,14);
	for (i = 0; i < 10; i++)
	{
		star(a[i], b[i]);
		floodfill(a[i], b[i], YELLOW);
	}
	drawmoon();
}


void starflower1()  //烟花绽放函数1
{
	double h, v, dv;  // 高度, 速度(方向向下),加速度(每 1/50 秒)
	{
		h = 470, v = 54, dv = 9.8 / 10;
		while (h >= 200)
		{
			h -= (v - dv / 2);
			v = v * 0.9;
			setcolor(GREEN);
			setfillcolor(RED);//填充颜色为蓝色
			fillcircle(300, int(h), 5);
			Sleep(20); // 延时
			// 擦掉球 
			setcolor(BLACK);
			setfillcolor(BLACK);//填充颜色为黑色
			fillcircle(300, int(h), 5);
			Sleep(10);
		}
	}
}


void starflower2()  //烟花绽放函数2
{
	int i = 0, j, n = 60, x = 300, y = 200, px, py;
	while (1)
	{
		if (i < 100)
		{
			for (j = 0; j < n; j++)
			{
				px = (int)(x + i*cos(j * 360 / n*PI / 180) + 1);
				py = (int)(y + i*sin(j * 360 / n*PI / 180) + 1);
				putpixel(px - 1, py, BLUE);
				putpixel(px, py + 1, BLUE);
				putpixel(px + 1, py - 1, YELLOW);
				putpixel(px, py - 1, YELLOW);
				putpixel(px + 1, py, RED);
				putpixel(px + 1, py + 1, RED);
			}
			//画圆擦掉
			Sleep(10);
			setfillcolor(BLACK);
			solidcircle(300, 200, 101);
		}
		i += 2;
		if (i >= 100)   break;
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彭就是我的姓i

你的鼓励是我创作的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值