#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;
}
C++实现圆面立体旋转(配合Easyx)(附上源码)
于 2023-07-08 23:32:44 首次发布