楕円スキャンBresenhamアルゴリズムVC++
4595 ワード
// MytestView.cpp : implementation of the CMytestView class
//
#include "stdafx.h"
#include "Mytest.h"
#include "math.h"
#include "MytestDoc.h"
#include "MytestView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMytestView
IMPLEMENT_DYNCREATE(CMytestView, CView)
BEGIN_MESSAGE_MAP(CMytestView, CView)
//{{AFX_MSG_MAP(CMytestView)
ON_COMMAND(ID_MENU_ZXSM, OnMenuZxsm)
ON_COMMAND(ID_MENU_YDSM, OnMenuYdsm)
ON_COMMAND(ID_MENU_TYSM, OnMenuTysm)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMytestView construction/destruction
CMytestView::CMytestView()
{
// TODO: add construction code here
}
CMytestView::~CMytestView()
{
}
BOOL CMytestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMytestView drawing
void CMytestView::OnDraw(CDC* pDC)
{
CMytestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMytestView printing
BOOL CMytestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMytestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMytestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMytestView diagnostics
#ifdef _DEBUG
void CMytestView::AssertValid() const
{
CView::AssertValid();
}
void CMytestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMytestDoc* CMytestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMytestDoc)));
return (CMytestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMytestView message handlers
void CMytestView::OnMenuZxsm()
{
// TODO: Add your command handler code here
}
void SetPixel8(CDC *pDC,int x,int y,COLORREF c)
{
pDC->SetPixel(x,y,c);
pDC->SetPixel(y,x,c);
pDC->SetPixel(-x,y,c);
pDC->SetPixel(y,-x,c);
pDC->SetPixel(-x,-y,c);
pDC->SetPixel(-y,-x,c);
pDC->SetPixel(x,-y,c);
pDC->SetPixel(-y,x,c);
}
void SetPixel4(CDC *pDC,int x,int y,COLORREF c)
{
pDC->SetPixel(x,y,c);
pDC->SetPixel(-x,y,c);
pDC->SetPixel(-x,-y,c);
pDC->SetPixel(x,-y,c);
}
void CMytestView::OnMenuYdsm()
{
// TODO: Add your command handler code here
CDC *pDC;
pDC=GetDC();
CRect rect;
GetClientRect(&rect);
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(rect.Width(),rect.Height());
pDC->SetViewportExt(rect.Width(),-rect.Height());
pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);
int r=100,x,y;
double d;
SetPixel8(pDC,0,r,RGB(0,0,255));
d=1.25-r;
for(x=0,y=r;x<=y;x++){
if(d>=0)
y--;
if(d>=0)
d=d+2*(x-y)+5;
else
d=d+2*x+3;
SetPixel8(pDC,x+1,y,RGB(0,0,255));
}
}
void CMytestView::OnMenuTysm()
{
// TODO: Add your command handler code here
CDC *pDC;
pDC=GetDC();
CRect rect;
GetClientRect(&rect);
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(rect.Width(),rect.Height());
pDC->SetViewportExt(rect.Width(),-rect.Height());
pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);
int a=200,b=100,x,y;
double d;
SetPixel4(pDC,0,b,RGB(0,0,255));
d=b*b+a*a*(-b+0.25);
for(x=0,y=b;x<=a*a/sqrt(a*a+b*b);x++){
if(d>=0)
y--;
if(d>=0)
d=d+b*b*(2*x+3)+a*a*(-2*y+2);
else
d=d+b*b*(2*x+3);
SetPixel4(pDC,x+1,y,RGB(0,0,255));
}
SetPixel4(pDC,a*a/sqrt(a*a+b*b),b*b/sqrt(a*a+b*b),RGB(0,0,255));
d=b*b*(x+0.5)*(x+0.5)+a*a*(y-1)*(y-1)-a*a*b*b;
for(x=a*a/sqrt(a*a+b*b),y=b*b/sqrt(a*a+b*b);y>0;y--){
if(d<=0)
x++;
if(d>=0)
d=d+a*a*(-2*y+3);
else
d=d+b*b*(2*x+2)+a*a*(-2*y+3);
SetPixel4(pDC,x,y-1,RGB(0,0,255));
}
}