⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphicdisp.cpp

📁 实现了区域填充已经其他画线功能
💻 CPP
字号:
#include "stdafx.h"
#include "GraphicDisp.h"

CGraphicDisp::CGraphicDisp(CDC *poDC)
{
	pDC=poDC;
}

void CGraphicDisp::lineDDA(int x1,int y1,int x2,int y2,COLORREF crColor)
{
	float increx,increy,x,y;
	int steps,i;
	
	CPoint p;

	if(abs(x2-x1)>abs(y2-y1))
		steps=abs(x2-x1);
	else
		steps=abs(y2-y1);
	
	increx=(float)(x2-x1)/steps;
	increy=(float)(y2-y1)/steps;

	x=x1;
	y=y1;

	for(i=1;i<=steps;i++)
	{
		p.x=x;
		p.y=y;
		pDC->SetPixel(p.x,p.y,crColor);
		x+=increx;
		y+=increy;
	}
}

void CGraphicDisp::lineBresenham(int x1, int y1, int x2, int y2, COLORREF crColor)
{
	int x, y, dx, dy, s1, s2, p, temp, interchange, i;
	CPoint pp;
	pp.x=x1;
	pp.y=y1;
	dx=abs(x2-x1);
	dy=abs(y2-y1);

	if(x2>x1)
		s1=1;
	else
		s1=-1;

	if(y2>y1)
		s2=1;
	else
		s2=-1;

	if(dy>dx)
	{
		temp=dx;
		dx=dy;
		dy=temp;
		interchange=1;
	}
	else
		interchange=0;

	p=2*dy-dx;
	for(i=1;i<=dx;i++)
	{
		pDC->SetPixel(pp.x,pp.y,crColor);
		if(p>=0)
		{
			if(interchange==0)
				pp.y=pp.y+s2;
			else
				pp.x=pp.x+s1;
			p=p-2*dx;
		}
		if(interchange==0)
			pp.x=pp.x+s1; 
		else
			pp.y=pp.y+s2;
		p=p+2*dy;
	}
}

void CGraphicDisp::MidpointCircle(int x0, int y0, int r, COLORREF crColor)
{
	int x,y;
	float d;
	x=0;
	y=r;
	d=5.0/4-r;

	while(x<=y)
	{
		putdot(x0,y0,x,y,crColor);
		if(d<0)
			d+=x*2.0+3;
		else
		{
			d+=2.0*(x-y)+5;
			y--;
		}
		x++;
	}
}

void CGraphicDisp::putdot(int x0, int y0, int x, int y, COLORREF crColor)
{
	pDC->SetPixel(x0,y0,RGB(255,0,0));
	pDC->SetPixel(x0+x,y0+y,crColor);
	pDC->SetPixel(x0+x,y0-y,crColor);
	pDC->SetPixel(x0-x,y0+y,crColor);
	pDC->SetPixel(x0-x,y0-y,crColor);
	pDC->SetPixel(x0+y,y0+x,crColor);
	pDC->SetPixel(x0+y,y0-x,crColor);
	pDC->SetPixel(x0-y,y0+x,crColor);
	pDC->SetPixel(x0-y,y0-x,crColor);
}

void CGraphicDisp::Pnarc(int x0, int y0, int r, COLORREF crColor)
{
	int x=0,y=r,f=0;
	while(x<=y)
	{
		putdot(x0,y0,x,y,crColor);
		if(f<=0)
		{
			f=f+2*x+1;
			x++;
		}
		else
		{
			f=f-2*y+1;
			y--;
		}
	}
}

⌨️ 快捷键说明

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