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

embedded/2024/10/18 17:29:32/

效果图片

在这里插入图片描述

代码

#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/embedded/128517.html

相关文章

2012年国赛高教杯数学建模D题机器人避障问题解题全过程文档及程序

2012年国赛高教杯数学建模 D题 机器人避障问题 图1是一个800800的平面场景图&#xff0c;在原点O(0, 0)点处有一个机器人&#xff0c;它只能在该平面场景范围内活动。图中有12个不同形状的区域是机器人不能与之发生碰撞的障碍物&#xff0c;障碍物的数学描述如下表&#xff1a…

简单说说 spring 是如何处理循环依赖问题的(源码解析)

聊聊源码 在spring 中&#xff0c;解决循环依赖的关键是三级缓存&#xff0c;缓存数据在 DefaultSingletonBeanRegistry类中 /** Cache of singleton objects: bean name to bean instance. */ //一级缓存&#xff0c;是最终生成的对象 private final Map<String, Object&…

数据结构——树和森林

目录 树的存储结构 1、双亲表示法 2、孩子链表 3、孩子兄弟表示法 树与二叉树的转换 将树转换为二叉树 将二叉树转换为树 森林与二叉树的转化 森林转换成二叉树 二叉树转换为森林 树和森林的遍历 1、 树的遍历&#xff08;三种方式&#xff09; 2、森林的遍历 树的存…

linux的学习第二天

1.vmware的功能&#xff1a; 快照 创建快照&#xff1a; 拍摄此虚拟机的快照&#xff1a;记录保存虚拟机的当前状态&#xff0c;如果系统出现故障&#xff0c;可以通过快照还原&#xff08;错删系统时可以找到快照的系统状态&#xff0c;然后恢复系统&#xff09; 恢复快照…

2024.10月11日--- SpringMVC拦截器

拦截器 1 回顾过滤器&#xff1a; Servlet规范中的三大接口&#xff1a;Servlet接口&#xff0c;Filter接口、Listener接口。 过滤器接口&#xff0c;是Servlet2.3版本以来&#xff0c;定义的一种小型的&#xff0c;可插拔的Web组件&#xff0c;可以用来拦截和处理Servlet容…

计算机毕设选题推荐【大数据专业】

计算机毕设选题推荐【大数据专业】 大数据专业的毕业设计需要结合数据的采集、存储、处理与分析等方面的技能。为帮助同学们找到一个适合且具有实践性的选题&#xff0c;我们为大家整理了50个精选的毕设选题。这些选题涵盖了大数据分析、处理技术、可视化等多个方向&#xff0…

问:JVM当中的垃圾分类怎么搞?

在Java中&#xff0c;JVM&#xff08;Java虚拟机&#xff09;的垃圾识别与分类是自动内存管理的重要组成部分。这一过程主要通过垃圾收集器&#xff08;Garbage Collector&#xff09;实现&#xff0c;旨在识别和回收不再被程序引用的对象&#xff0c;以释放内存空间。 1. 垃圾…

Python网络爬虫入门指南

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;Java Fans的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏…