20201017-【C、C++】跳动的爱心

news/2024/10/19 11:08:53/

效果图片

在这里插入图片描述

代码

#include "graphics.h"
#include <conio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>struct Point {double x, y;COLORREF color;
};COLORREF colors[256] = {RGB(255,32,83),RGB(252,222,250),RGB(255,0,0),RGB(255,0,0),RGB(255,2,2),RGB(255,0,8),RGB(255,5,5),
};const int xScreen = 1200;
const int yScreen = 800;
const double PI = 3.1426535159;
const double e = 2.71828;
const double averag_distance = 0.162;
const int quantity = 506;
const int circles = 210;
const int frames = 20;
Point origin_points[quantity];
Point points[circles * quantity];
IMAGE images[frames];
double screen_x(double x) {x += xScreen / 2;return x;
}
double screen_y(double y) {y = -y + yScreen / 2;return y;
}int creat_random(int x1, int x2) {if (x2 > x1)return rand() % (x2 - x1 + 1) + x1;
}
void creat_data()
{int index = 0;double x1 = 0, y1 = 0, x2 = 0, y2 = 0;for (double radian = 0.1; radian <= 2 * PI; radian += 0.005){x2 = 16 * pow(sin(radian), 3);y2 = 13 * cos(radian) - 5 * cos(2 * radian) - 2 * cos(3 * radian) - cos(4 * radian);double distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));if (distance > averag_distance) {x1 = x2, y1 = y2;origin_points[index].x = x2;origin_points[index++].y = y2;}}index = 0;for (double size = 0.l, lightness = 1.5; size <= 20; size += 0.1){double success_p = 1 / (1 + pow(e, 8 - size / 2));if (lightness > 1)lightness -= 0.0025;for (int i = 0; i < quantity; ++i){if (success_p > creat_random(0, 100) / 100.0){COLORREF color = colors[creat_random(0, 6)];points[index].color = RGB(GetRValue(color) / lightness, GetGValue(color) / lightness, GetBValue(color) / lightness);points[index].x = size * origin_points[i].x + creat_random(-4, 4);points[index++].y = size * origin_points[i].y + creat_random(-4, 4);}}}int points_size = index;for (int frame = 0; frame < frames; ++frame){images[frame] = IMAGE(xScreen, yScreen);SetWorkingImage(&images[frame]);for (index = 0; index < points_size; ++index){double x = points[index].x, y = points[index].y;double distance = sqrt(pow(x, 2) + pow(y, 2));double diatance_increase = -0.0009 * distance * distance + 0.35714 * distance + 5;double x_increase = diatance_increase * x / distance / frames;double y_increase = diatance_increase * y / distance / frames;points[index].x += x_increase;points[index].y += y_increase;setfillcolor(points[index].color);solidcircle(screen_x(points[index].x), screen_y(points[index].y), 1);}for (double size = 17; size < 23; size += 0.3){for (index = 0; index < quantity; ++index){if ((creat_random(0, 100) / 100.0 > 0.6 && size >= 20) || (size < 20 && creat_random(0, 100) / 100.0>0.95)){double x, y;if (size >= 20){x = origin_points[index].x * size + creat_random(-frame * frame / 5 - 15, frame * frame / 5 + 15);y = origin_points[index].y * size + creat_random(-frame * frame / 5 - 15, frame * frame / 5 + 15);}else{x = origin_points[index].x * size + creat_random(-5, 5);y = origin_points[index].y * size + creat_random(-5, 5);}setfillcolor(colors[creat_random(0, 6)]);solidcircle(screen_x(x), screen_y(y), 1);}}}}SetWorkingImage();
}
int main()
{initgraph(xScreen, yScreen);BeginBatchDraw();srand(time(0));creat_data();bool extend = true, shrink = false;for (int frame = 0; !_kbhit();){putimage(0, 0, &images[frame]);FlushBatchDraw();Sleep(20);cleardevice();if (extend)frame == 19 ? (shrink = true, extend = false) : ++frame;elseframe == 0 ? (shrink = false, extend = true) : --frame;}EndBatchDraw();closegraph();return 0;
}

EasyX插件

下载地址:https://easyx.cn/t/download
在这里插入图片描述

安装:双击exe文件,下一步,安装
在这里插入图片描述
如果安装成功后,引用还是报错的话,就去安装路径里找到graphics.h文件复制到项目文件夹中,然后在代码中使用#include "graphics.h"语句引用
在这里插入图片描述

项目源码

链接: https://pan.baidu.com/s/1jMD77lqrRy7QyP6gwk8pog?pwd=4vqe
提取码: 4vqe


http://www.ppmy.cn/news/1540239.html

相关文章

启动service报错ORA-44317: database open read-only

ADG&#xff08;RAC&#xff09;备库环境&#xff0c;srvctl添加service服务成功&#xff0c;启动service时报错ORA-44317: database open read-only。 这是预期行为&#xff0c; 使用“srvctl add service -d <db_name> -s <service_name>”创建服务时&#xff0c…

【c++/C#】 混编的多线程,thread_local,

C 通过 thread_local 变量来实现线程局部存储&#xff08;Thread-Local Storage, TLS&#xff09;&#xff0c;而 C 动态库并不需要直接感知线程是从 C 还是 C# 端创建的。线程的管理、调度等由操作系统处理&#xff0c;而 thread_local 的工作机制是与具体的编程语言无关的。让…

Flink时间窗口程序骨架结构

前言 Flink 作业的基本骨架结构包含三部分&#xff1a;创建执行环境、定义数据处理逻辑、提交并执行Flink作业。 日常大部分 Flink 作业是基于时间窗口计算模型的&#xff0c;同样的&#xff0c;开发一个Flink时间窗口作业也有一套基本的骨架结构&#xff0c;了解这套结构有助…

LLM 相关 API Key 配置速查

文章目录 LangChain智谱DashScope - QwenMoonshot AI - KimiOpenAItavily API Key 是个很简单的功能&#xff0c;但网站一大&#xff0c;就忘记在哪里&#xff0c;这里记录下 环境变量 及 Python 中常用设置代码为&#xff1a; import getpass import os# 简单配置 OPENAI_API…

2024年科技赋能教育,AI辅导引领新趋势

在近日举行的2024年中国国际服务贸易交易会上&#xff0c;教育服务展区凭借科技与教育深度融合的特色&#xff0c;成功吸引了大量参观者的注意。特别是主打AI个性化辅导的学习产品&#xff0c;更是成为了众多家长眼中的“省妈神器”。 “大语言模型”技术的快速发展及其科学化…

贪吃蛇游戏(代码篇)

我们并不是为了满足别人的期待而活着。 前言 这是我自己做的第五个小项目---贪吃蛇游戏&#xff08;代码篇&#xff09;。后期我会继续制作其他小项目并开源至博客上。 上一小项目是贪吃蛇游戏&#xff08;必备知识篇&#xff09;&#xff0c;没看过的同学可以去看看&#xf…

ShuffleNet通道混合轻量级网络的深入介绍和实战

ShuffleNet是一种轻量级的深度学习模型&#xff0c;它在保持MobileNet的Depthwise Separable Convolution&#xff08;深度可分离卷积&#xff09;的基础上&#xff0c;引入了通道混合&#xff08;Channel Shuffle&#xff09;机制&#xff0c;以进一步提升模型的性能和效率。 …

基于微信小程序的购物系统【附源码、文档】

博主介绍&#xff1a;✌IT徐师兄、7年大厂程序员经历。全网粉丝15W、csdn博客专家、掘金/华为云//InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专栏推荐订阅&#x1f447;&#x1f3…