【无标题】

//七夕爱心

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值