【VC开源代码栏目提醒】:网学会员--在 VC开源代码编辑为广大网友搜集整理了:WoodView.cpp绩等信息,祝愿广大网友取得需要的信息,参考学习。
// WoodView.cpp : implementation of the CWoodView class
//
#include "stdafx.h"
#include "Wood.h"
#include "WoodDoc.h"
#include "WoodView.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWoodView
IMPLEMENT_DYNCREATE(CWoodView, CView)
BEGIN_MESSAGE_MAP(CWoodView, CView)
//{{AFX_MSG_MAP(CWoodView)
ON_COMMAND(ID_WOOD1, OnWood1)
ON_COMMAND(ID_WOOD2, OnWood2)
ON_COMMAND(ID_STONE1, OnStone1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWoodView construction/destruction
CWoodView::CWoodView()
{
// TODO: add construction code here
}
CWoodView::~CWoodView()
{
}
BOOL CWoodView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CWoodView drawing
void CWoodView::OnDraw(CDC* pDC)
{
CWoodDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CWoodView diagnostics
#ifdef _DEBUG
void CWoodView::AssertValid() const
{
CView::AssertValid();
}
void CWoodView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CWoodDoc* CWoodView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWoodDoc)));
return (CWoodDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWoodView message handlers
#define PI 3.14159265359
COLORREF CWoodView::WoodGrain(int u, int w, int v)
{
float radius,angle;
int grain;
COLORREF col;
radius=sqrt(u*u+w*w);
if(w==0)
angle=PI/2;
else
angle=atan(u/w);
radius=radius+2*sin(20*angle+v/150);
grain=(int)(radius*(rand()%7))%180;
if(grain<40)
col=RGB(180,180,180);
else
col=RGB(120,120,120);
return col;
}
void CWoodView::OnWood1()
{
CDC* pDC=GetDC();
for(int w=0;w<250;w++)
for(int u=0;u<250;u++)
pDC->SetPixel(u,w,WoodGrain(u,w,0));
ReleaseDC(pDC);
}
void CWoodView::OnWood2()
{
CDC* pDC=GetDC();
for(int w=0;w<250;w++)
for(int v=0;v<250;v++)
pDC->SetPixel(v,w,WoodGrain(0,w,v));
ReleaseDC(pDC);
}
void CWoodView::OnStone1()
{
CDC* pDC=GetDC();
for(int w=0;w<250;w++)
for(int v=0;v<250;v++)
pDC->SetPixel(v,w,StoneGrain(0,w,v));
ReleaseDC(pDC);
}
COLORREF CWoodView::StoneGrain(int u, int w, int v)
{
COLORREF col;
int grain=(int)rand()%80;
if(grain<40)
col=RGB(180,180,180);
else
col=RGB(120,120,120);
return col;
}