📄 ellipse.cpp
字号:
// Ellipse.cpp: implementation of the Ellipse class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Graph.h"
#include "Ellipse.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Ellipse::Ellipse()
{
}
Ellipse::~Ellipse()
{
}
#define ROUND(a) ((int)(a+0.5))
void Ellipse::ellispeMidpoint(CDC *pDC, CPoint ptCenter, int nRx, int nRy, COLORREF color)
{
int Rx2=nRx*nRx;
int Ry2=nRy*nRy;
int twoRx2=2*Rx2;
int twoRy2=2*Ry2;
int p;
CPoint pt;
pt.x=0;pt.y=nRy;
int px=0;int py=twoRx2*pt.y;
PlotPoints(pDC,ptCenter,pt,color);
/*Region1*/
p=ROUND(Ry2-(Rx2*nRy)+(0.25*Rx2));
while(px<py){
pt.x++;
px+=twoRy2;
if(p<0)p+=Ry2+px;
else{
pt.y--;
py-=twoRx2;
p+=Ry2+px-py;
}
PlotPoints(pDC,ptCenter,pt,color);
}
/*Region2*/
p=ROUND(Ry2*(pt.x+0.5)*(pt.x+0.5)+Rx2*(pt.y-1)*(pt.y-1)-Rx2*Ry2);
while(pt.y>0){
pt.y--;
py-=twoRx2;
if(p>0)
p+=Rx2-py;
else{
pt.x++;
px+=twoRy2;
p+=Rx2-py+px;
}
PlotPoints(pDC,ptCenter,pt,color);
}
}
void Ellipse::PlotPoints(CDC *pDC, CPoint ptCenter, CPoint pt, COLORREF color)
{
pDC->SetPixel(ptCenter.x+pt.x,ptCenter.y+pt.y,color);
pDC->SetPixel(ptCenter.x-pt.x,ptCenter.y+pt.y,color);
pDC->SetPixel(ptCenter.x+pt.x,ptCenter.y-pt.y,color);
pDC->SetPixel(ptCenter.x-pt.x,ptCenter.y-pt.y,color);
}
void Ellipse::draw(CDC *pDC)
{
CPoint ptCenter;
ptCenter.x=(m_ptBegin.x+m_ptEnd.x)/2;
ptCenter.y=(m_ptBegin.y+m_ptEnd.y)/2;
int nRx=abs(m_ptBegin.x-m_ptEnd.x)/2;
int nRy=abs(m_ptBegin.y-m_ptEnd.y)/2;
ellispeMidpoint(pDC, ptCenter,nRx,nRy,m_color);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -