C++实现圆面立体旋转(配合Easyx)(附上源码)

#include <iostream>
using namespace std;
#include <easyx.h>
#include <ctime>
#include <string>
#include <algorithm>
#include <math.h>

typedef unsigned long int ul_position,ul_radius,ul_perimeter,ul_area;
typedef unsigned char A_RGB;
typedef A_RGB* Color_RGB;


class Circle
{
private:
    ul_position x;          //x坐标 单位px
    ul_position y;          //y坐标 单位px
    ul_radius r;            //半径  单位px
    
    ul_perimeter p;         //周长
    ul_area s;              //面积

    Color_RGB crl;           //一个动态数组,存放三个元素R、G、B的值——圆框的颜色
    Color_RGB crf;           //一个动态数组,存放三个元素R、G、B的值——圆填充的颜色

public:
    Circle(ul_position x,ul_position y,ul_radius r)
    {
        this->x = x;
        this->y = y;
        this->r = r;
        this->crl = new A_RGB[3];
        (this->crl)[0] = 0;
        (this->crl)[1] = 0;
        (this->crl)[2] = 0;

        this->crf = new A_RGB[3];
        (this->crf)[0] = 255;
        (this->crf)[1] = 255;
        (this->crf)[2] = 255;
    }

    ~Circle()
    {
        this->x = 0;
        this->y = 0;
        this->r = 0;

        delete[] (this->crl);
        delete[] (this->crf);
    }


public:

    enum select_spin
    {
        Turn,NTurn
    };
    void show_Three_Dimensional_Spin(unsigned int spin_speed = 20)
    {
        double temp_x1 = this->x;
        double temp_x2 = this->x;
        ul_position gradual_change_r = this->r;

        temp_x1 -= gradual_change_r;
        temp_x2 += gradual_change_r;
        
        enum select_spin select = NTurn;

        setlinecolor(RGB((this->crl)[0],(this->crl)[1],(this->crl)[2]));
        setfillcolor(RGB((this->crf)[0],(this->crf)[1],(this->crf)[2]));
        while(true)
        {
           cleardevice();
            
           fillellipse(temp_x1,y - r,temp_x2,y + r);
           //line(this->x,this->y - r,this->x,this->y + r);
           FlushBatchDraw();
           switch(select)
            {
                case NTurn:
                {
                    if((temp_x1 < this->x) && (temp_x1 >= (this->x - this->r)))
                    {
                        temp_x1 += (this->r) / 2000.0 * spin_speed;
                        temp_x2 -=  (this->r) / 2000.0 * spin_speed;
                    }
                    else
                    {
                        select = Turn;
                    } 
                }
                break;
                case Turn:
                {
                    if(temp_x2 < (this->x + this->r))
                    {
                        temp_x1 -=  (this->r) / 2000.0 * spin_speed;
                        temp_x2 +=  (this->r) / 2000.0 * spin_speed;

                        (temp_x1 < (this->x - this->r)) ? (temp_x1 = (this->x) - (this->r)) : 0;
                        (temp_x2 > (this->x + this->r)) ? (temp_x2 = this->x + this->r) : 0; 
                    }
                    else
                    {
                        select = NTurn;
                    } 
                }
                break;

            }
        }
    }

    void show_Static_Planar_Graph()
    {
        setlinecolor(RGB((this->crl)[0],(this->crl)[1],(this->crl)[2]));
        setfillcolor(RGB((this->crf)[0],(this->crf)[1],(this->crf)[2]));
        fillcircle(this->x,this->y,this->r);
        FlushBatchDraw();

    }

    void set_Fill_Color_RGB(Color_RGB temp_crf = NULL)
    {
        if(NULL != temp_crf)
        {
            (this->crf)[0] = temp_crf[0];
            (this->crf)[1] = temp_crf[1];
            (this->crf)[2] = temp_crf[2];   
        }
        
    }

    void set_Line_Color_RGB(Color_RGB temp_crl = NULL)
    {
        if(NULL != temp_crl)
        {
            (this->crl)[0] = temp_crl[0];
            (this->crl)[1] = temp_crl[1];
            (this->crl)[2] = temp_crl[2];   
        }
    }

};



int main()
{

       // 初始化图形界面
    initgraph(640, 480);
    BeginBatchDraw();
    Circle c(300,200,100);
    unsigned char cr[3] = {26,168,221};
    c.set_Fill_Color_RGB(cr);
    c.show_Three_Dimensional_Spin(1);

    EndBatchDraw();
    // 关闭图形界面
    closegraph();



    system("pause");
    return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小艺术生◎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值