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

ops/2024/10/18 19:20:26/

效果图片

在这里插入图片描述

代码

#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/ops/126543.html

相关文章

vue3之生命周期钩子

Vue 组件实例生命周期 每个 Vue 组件实例在创建时都需要经历一系列的初始化步骤&#xff0c;比如设置好数据侦听&#xff0c;编译模板&#xff0c;挂载实例到 DOM&#xff0c;以及在数据改变时更新 DOM。在此过程中&#xff0c;它也会运行被称为生命周期钩子的函数&#xff0c…

机器学习_线性回归_线性回归过拟合和欠拟合+正则化线性模型学习总结

线性回归的缺陷--欠拟合和过拟合 欠拟合: 简介 训练集和测试集表现都不怎么样, 模型太简单 产生原因: 学习到的特征太少 改进方法: 1.添加其他特征 组合 泛化 相关性 上下文特征,平台特征等 2.添加多项式特征, 将低次项模型变成高次项模型 过拟合: 简介 原始特征过多,存在嘈杂特…

【python】数据容器:dict(字典、映射)

目录 数据容器入门数据容器&#xff1a;list&#xff08;列表&#xff09;list&#xff08;列表&#xff09;的遍历数据容器&#xff1a;tuple&#xff08;元组&#xff09;数据容器&#xff1a;str&#xff08;字符串&#xff09;数据容器的切片数据容器&#xff1a;set&…

G-Set(增长集合,Grow-Only Set)

一、概念 G-Set&#xff08;增长集合&#xff0c;Grow-Only Set&#xff09;是一种冲突自由复制数据类型&#xff08;Conflict-Free Replicated Data Type, CRDT&#xff09;&#xff0c;用于在分布式系统中同步和合并数据&#xff0c;而不需要中央协调器。G-Set 支持两种操作…

LLM - 使用 Neo4j 可视化 GraphRAG 构建的 知识图谱(KG) 教程

欢迎关注我的CSDN&#xff1a;https://spike.blog.csdn.net/ 本文地址&#xff1a;https://spike.blog.csdn.net/article/details/142938982 免责声明&#xff1a;本文来源于个人知识与公开资料&#xff0c;仅用于学术交流&#xff0c;欢迎讨论&#xff0c;不支持转载。 Neo4j …

深入了解React 工作原理是什么

前端面试题包括ECMScript,TypeScript,Nodejs,React,Webgl,Webpack,Threejs等还在整理中&#xff0c;在线地址前端面试题&#xff0c;源码地址大家多多支持才有动力给大家分享更多好的面试题。 React 的工作原理基于以下几个关键概念&#xff1a;虚拟 DOM&#xff08;Virtual D…

@PostConstruct和afterPropertiesSet方法执行多次的原因

近日&#xff0c;遇到一个问题&#xff0c;PostConstruct方法会莫名执行多次&#xff0c;单看代码看不出问题&#xff0c;印象中也只会在bean初始化的时候执行一次而已。 然后问AI&#xff0c;问百度&#xff0c;没找到原因。 后面自己猜测&#xff08;现在都是面向猜测编程&am…

大数据治理:定义、重要性及实践

大数据治理&#xff1a;定义、重要性及实践 引言 大数据治理是当代企业信息管理和数据管理的重要环节&#xff0c;它涉及到数据的获取、处理、存储、安全、质量、生命周期管理等方方面面。随着信息技术的迅猛发展和数据量的爆炸式增长&#xff0c;大数据治理已经成为企业提升…