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

devtools/2024/10/18 19:30:42/

效果图片

在这里插入图片描述

代码

#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/devtools/126798.html

相关文章

IDEA下载安装

文章目录 1、下载安装包2、安装IDEA3、全局配置4、安装插件5、关闭合并菜单栏 1、下载安装包 IDEA官网下载最新IDEA。 上面的ULtimate是旗舰版&#xff0c;试用30天&#xff0c;之后是需要收费的&#xff0c;下面黑色区域的Community是社区版&#xff0c;功能不如旗舰版丰富&a…

美业saas系统能解决美容行业哪些痛点问题?博弈美业收银系统管理系统拓客系统分享

美业SAAS系统是指基于互联网的软件即服务系统&#xff0c;旨在帮助美容行业解决各种痛点问题。通过整合管理、营销推广、客户关系和运营等方面&#xff0c;美业SAAS系统能够为美容行业提供全方位的解决方案。 下面博弈美业将从各方面因素分析美业SAAS系统能够解决的问题&#x…

【热门】软件管理系统erp,研+产+供+销+业+财+数据一体

随着科技的进步,原有农业种植方式已经不能满足社会发展的需要,必须对传统的农业进行技术更新和改造。经过多年的实践,人们总结出一种新的种植方法——温室农业,即“用人工设施控制环境因素,使作物获得最适宜的生长条件,从而延长生产季节,获得最佳的产出”。这种农业生产方式…

C#基础-面向对象的七大设计原则

目录 1.开放封闭原则&#xff08;OCP&#xff09; 2.单一职责原则&#xff08;SRP&#xff09; 3.依赖倒置原则&#xff08;DIP&#xff09; 4.里氏替换原则&#xff08;LSP&#xff09; 5.接口隔离原则&#xff08;ISP&#xff09; 6.合成复用原则&#xff08;CRP&#…

Faceware + 虚幻引擎MetaHuman:打造超写实风格角色面部动画

在影视、游戏和虚拟现实的制作中&#xff0c;逼真的面部动画是增强角色表现力和提升观众沉浸感的关键。近年来&#xff0c;得益于面部捕捉技术和数字人创建工具的飞速进步&#xff0c;数字内容的创作达到了新的高度。Faceware面部捕捉系统和虚幻引擎&#xff08;Unreal Engine&…

平台上新 | 智能分析——你的智能体调优工具已上线!

&#x1f4e2;「智能分析」已全量上线 帮助开发者伙伴快速定位智能体可优化项&#xff0c;并提供优化建议&#xff0c;从而提升智能体质量与流量获取能力。 &#x1f389;「调优之星」优先推荐活动 功能尝鲜体验期&#xff0c;开发者对任一智能体完成任一“可优化项目”&…

C#数据类型与变量声明

在C#编程中&#xff0c;数据类型和变量声明是构建程序的基础。数据类型定义了变量可以存储的数据的类型和范围&#xff0c;而变量声明则是为这些数据类型分配内存空间的过程。 C# 数据类型 C# 中的数据类型可以分为以下几类&#xff1a; 值类型&#xff08;Value Types&#…

Linux重点yum源配置

1.配置在线源 2.配置本地源 3.安装软件包 4.测试yum源配置 5.卸载软件包