line.cpp

来自「这个是计算机图形学的课程设计的全部 内容。」· C++ 代码 · 共 53 行

CPP
53
字号
// Line.cpp: implementation of the Line class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Graph.h"
#include "Line.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Line::Line()
{

}

Line::~Line()
{

}

void Line::LineBres(CDC *pDC, CPoint pStart, CPoint pEnd, COLORREF color)
{int dx=abs(pStart.x-pEnd.x),dy=abs(pStart.y-pEnd.y);
int p=2*dy-dx;
int twoDy=2*dy,twoDyDx=2*(dy-dx);
int x,y,xEnd;
if(pStart.x>pEnd.x)
{pStart.x=pEnd.x;y=pEnd.y;xEnd=pStart.x;}
else{x=pStart.x;y=pStart.y;
xEnd=pEnd.x;}
pDC->SetPixel(x,y,color);
while(x<xEnd)
{x++;
if(p<0) p+=twoDy;
else{y++;
p+=twoDyDx;}
pDC->SetPixel(x,y,color);
}

}

void Line::draw(CDC *pDC)
{
LineBres(pDC,m_ptBegin,m_ptEnd,m_color);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?