C ++ using the Draw cardioid EasyX

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_43669941/article/details/89857255

code show as below

#include <graphics.h>
#include <cmath>
#include <conio.h>

constexpr auto PI = 3.1415926;
constexpr auto ONE_ANGLE = PI / 180;

//该函数用于绘制心形线
//_x: x方向上的偏移量
//_y: y方向上的偏移量
//a: 缩放倍数
void cardioid(int _x, int _y, int a)
{
	int x1, y1, x2, y2;
	double angle = 0;
	while (angle <= 2 * PI)
	{
		x1 = a * (2 * sin(angle) + sin(2 * angle)) + _x;
		y1 = a * (2 * cos(angle) + cos(2 * angle)) + _y;
		angle += ONE_ANGLE;
		x2 = a * (2 * sin(angle) + sin(2 * angle)) + _x;
		y2 = a * (2 * cos(angle) + cos(2 * angle)) + _y;
		line(x1, y1, x2, y2);

		Sleep(5);
	}

}

int main(void)
{
	initgraph(640, 480);
	setlinecolor(RGB(255, 0, 0));

	cardioid(320, 240, 50);

	auto ret = _getch();
	closegraph();
	return 0;
}

Results are as follows

Guess you like

Origin blog.csdn.net/weixin_43669941/article/details/89857255