//七夕爱心
#include<graphics.h>
#include<Windows.h>
#include <cmath> //sin,cos,
#include <conio.h> //_getch()
#include<math.h>
//constexpr auto PI = 3.1415926;
//constexpr auto ONE_ANGLE = PI / 180;
#define x2_init -100;
#define p 3.1415926; //p与括号问题
//函数与系数及帧数处理关系问题
#define Y_REPAIR 110 //y的补充
//该函数用于绘制心形线
//_x: x方向上的偏移量
//_y: y方向上的偏移量
//a: 缩放倍数
void cardioid(int _x, int _y, int a)
{
double x1=0, y1=0, x2, y2;
double init_count = y1;
x2 = -2;
while (x1 <= 2 ) {
x1 = x2 ;
y1 = a * (pow(cos(1 - abs(x1)), -1) - 3.1415926) + _y;
x2 = x1 + 0.01;
y2 = a * (pow(cos(1 - abs(x2)), -1) - 3.1415926) + _y;
line(a*x1+_x, y1, a*x2+_x, y2);
Sleep(1);
}
x2 = 1; x1 = 1;
while (x1 > -0.98) {
x1 = x2;
y1 = 2.6 * a * sqrt(1 - pow((abs(x1)), 2)) + _y;
x2 = x1 - 0.01;
y2 = 2.6 * a * sqrt(1 - pow((abs(x2)), 2)) + _y;
line(2 * a * x1 + _x, y1- Y_REPAIR, 2 * a * x2 + _x, y2-Y_REPAIR);
Sleep(1);
}
line(160,99,159,109);
line(159,109,163,120);
}
int main(void)
{
initgraph(640, 480);
setlinecolor(RGB(255, 0, 0));
setlinestyle(PS_SOLID, 5);
cardioid(320, 200, 80);
auto ret = _getch();//类似于system("pause")的作用;
closegraph();
return 0;
}