📄 newcloudview.cpp
字号:
// NewCloudView.cpp : implementation of the CNewCloudView class
//
#include "stdafx.h"
#include "NewCloud.h"
#include "TuoyuanDlg.h"
#include "NewCloudDoc.h"
#include "NewCloudView.h"
#include <math.h>
#include "InputDlg.h"
#include "SinDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define Pi 3.1415626
#define NUM 500
/////////////////////////////////////////////////////////////////////////////
// CNewCloudView
IMPLEMENT_DYNCREATE(CNewCloudView, CView)
BEGIN_MESSAGE_MAP(CNewCloudView, CView)
//{{AFX_MSG_MAP(CNewCloudView)
ON_COMMAND(ID_CIRCLE, OnCircle)
ON_COMMAND(ID_TUOYUAN, OnTuoyuan)
ON_COMMAND(ID_Sin, OnSin)
ON_COMMAND(ID_Sin2, OnSin2)
ON_COMMAND(ID_Sin3, OnSin3)
ON_COMMAND(ID_Cos1, OnCos1)
ON_COMMAND(ID_Cos2, OnCos2)
ON_COMMAND(ID_Cos3, OnCos3)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CNewCloudView construction/destruction
CNewCloudView::CNewCloudView()
{
// TODO: add construction code here
// Draw=false;
}
CNewCloudView::~CNewCloudView()
{
}
BOOL CNewCloudView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CNewCloudView drawing
void CNewCloudView::OnDraw(CDC* pDC)
{
CNewCloudDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// if(Draw)
// {
float x,y;
float r=0;
float a=0;
float b=0;
float delx=0;
float dely=0;
float Fx;
CPen pen2(PS_SOLID, 1, RGB(255,0,0));
int oldmode = pDC->GetROP2();
CPen* oldpen = pDC->SelectObject(&pen2);//指定绘制笔;
//设置为“空”刷,既不填充。
CBrush* oldbrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
pDC->SetROP2(R2_COPYPEN);//指定绘制模式
if(pDoc->flag==1)
{
for (int i=0;i<point.size();i++)
//for (int i=0;i<20;i++)
{
x=point[i].x;
y=point[i].y;
r=point[i].r;
pDC->Ellipse(x-r,y-r,x+r,y+r);
}
// point.clear();
}
else if(pDoc->flag==2)
{
for (int i=0;i<typoint.size();i++)
{
x=typoint[i].x;
y=typoint[i].y;
a=typoint[i].a;
b=typoint[i].b;
pDC->Ellipse(x-a,y-b,x+a,y+b);
}
// typoint.clear();
}
else if(pDoc->flag==3)
{
for(int i=0;i<Spoint.size();i++)
{
delx=Spoint[i].x;
dely=Spoint[i].y;
if(pDoc->Sflag==1)
{
for(float k=0;k<16*Pi;k++)
{
Fx=100*sin(k+delx);
pDC->SetPixel(250+int(k+delx),int(Fx)+250,RGB(255,0,0));
}
}
else if(pDoc->Sflag==2)
{
for(float k=0;k<16*Pi;k++)
{
Fx=100*sin(k+delx)-dely;
pDC->SetPixel(250+int(k),int(Fx)+250,RGB(255,0,0));
}
}
else if(pDoc->Sflag==3)
{
for(float k=0;k<16*Pi;k++)
{
Fx=100*sin(k+delx)-dely;
pDC->SetPixel(250+int(k+delx),int(Fx)+250,RGB(255,0,0));
}
}
}
}
else if(pDoc->flag==4)
{
for(int i=0;i<Spoint.size();i++)
{
delx=Spoint[i].x;
dely=Spoint[i].y;
if(pDoc->Sflag==1)
{
for(float k=0;k<16*Pi;k++)
{
Fx=100*cos(k+delx);
pDC->SetPixel(250+int(k+delx),int(Fx)+250,RGB(255,0,0));
}
}
else if(pDoc->Sflag==2)
{
for(float k=0;k<16*Pi;k++)
{
Fx=100*cos(k+delx)-dely;
pDC->SetPixel(250+int(k),int(Fx)+250,RGB(255,0,0));
}
}
else if(pDoc->Sflag==3)
{
for(float k=0;k<16*Pi;k++)
{
Fx=100*cos(k+delx)-dely;
pDC->SetPixel(250+int(k+delx),int(Fx)+250,RGB(255,0,0));
}
}
}
}
oldpen=pDC->SelectObject(&pen2);
pen2.DeleteObject();
pDC->SetROP2(oldmode);
pDC->SelectObject(oldbrush);
CPen pen(PS_SOLID,1,RGB(255,0,0));//定义红色画笔
CPen* pOldPen=pDC->SelectObject(&pen);
pDC->SelectObject(pOldPen); //恢复画笔
// }
// Draw=false;
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CNewCloudView printing
BOOL CNewCloudView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CNewCloudView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CNewCloudView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CNewCloudView diagnostics
#ifdef _DEBUG
void CNewCloudView::AssertValid() const
{
CView::AssertValid();
}
void CNewCloudView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CNewCloudDoc* CNewCloudView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNewCloudDoc)));
return (CNewCloudDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CNewCloudView message handlers
void CNewCloudView::OnCircle()
{
// TODO: Add your command handler code here
CNewCloudDoc* pDoc = GetDocument();
pDoc->flag=1;
CInputDlg dlg;
float En,He,X,Y,R;
if(dlg.DoModal()!=IDOK)
{
return;
}
En=dlg.m_En;
He=dlg.m_He;
X=dlg.m_X;
Y=dlg.m_Y;
R=dlg.m_R;
BeginWaitCursor();
NewCloudGenerator(En,He, X, Y, R);
// Draw=TRUE;
Invalidate();
UpdateWindow();
EndWaitCursor();
}
void CNewCloudView::NewCloudGenerator(float En, float He, float X, float Y, float R)
{
float exi,xi,yi,ri;
float x=X;
float y=Y;
float r=R;
srand((unsigned)time(NULL));
point.clear();
for (int i=0; i<NUM; i++)
{
exi=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*He+En;
exi=exi*2;
xi=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*exi*50+x;
yi=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*exi*50+y;
ri=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*exi+r;
pt.x=xi;
pt.y=yi;
pt.r=ri;
point.push_back(pt);
}
}
void CNewCloudView::OnTuoyuan()
{
// TODO: Add your command handler code here
CNewCloudDoc* pDoc = GetDocument();
pDoc->flag=2;
CTuoyuanDlg dlg;
float En,He,X,Y,A,B;
if(dlg.DoModal()!=IDOK)
{
return;
}
En=dlg.m_En;
He=dlg.m_He;
X=dlg.m_X;
Y=dlg.m_Y;
A=dlg.m_a;
B=dlg.m_b;
BeginWaitCursor();
TuoyuanCloud(En,He,X,Y,A,B);
// Draw=TRUE;
Invalidate();
UpdateWindow();
EndWaitCursor();
}
void CNewCloudView::TuoyuanCloud(float En, float He, float x, float y, float a, float b)
{
float exi,xi,yi,ai,bi;
srand((unsigned)time(NULL));
typoint.clear();
for (int i=0; i<NUM; i++)
{
exi=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*He+En;
exi=exi*2;
xi=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*exi*20+x;
yi=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*exi*20+y;
ai=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*exi*20+a;
bi=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*exi*20+b;
ty.x=xi;
ty.y=yi;
ty.a=ai;
ty.b=bi;
typoint.push_back(ty);
}
}
//void CNewCloudView::OnPaint()
//{
// CPaintDC dc(this); // device context for painting
// AfxGetMainWnd()->UpdateWindow();
//
//
//}
void CNewCloudView::OnSin()
{
// TODO: Add your command handler code here
CNewCloudDoc* pDoc = GetDocument();
pDoc->flag=3;
pDoc->Sflag=1;
CSinDlg dlg;
float Ex,En,He;
if(dlg.DoModal()!=IDOK)
{
return;
}
En=dlg.m_En;
He=dlg.m_He;
Ex=dlg.m_Ex;
BeginWaitCursor();
SinCloudGenerator(Ex, En, He);
// Draw=TRUE;
Invalidate();
UpdateWindow();
EndWaitCursor();
}
void CNewCloudView::SinCloudGenerator(float Ex, float En, float He)
{
float delx;
float dely;
float Eni;
srand((unsigned)time(NULL));
Spoint.clear();
for (int i=0; i<NUM; i++)
{
Eni=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*He+En;
delx=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*Eni+Ex;
dely=(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*Eni+Ex;
St.x=delx;
St.y=dely;
Spoint.push_back(St);
}
}
void CNewCloudView::OnSin2()
{
// TODO: Add your command handler code here
CNewCloudDoc* pDoc = GetDocument();
pDoc->flag=3;
pDoc->Sflag=2;
CSinDlg dlg;
float Ex,En,He;
if(dlg.DoModal()!=IDOK)
{
return;
}
En=dlg.m_En;
He=dlg.m_He;
Ex=dlg.m_Ex;
BeginWaitCursor();
SinCloudGenerator(Ex, En, He);
// Draw=TRUE;
Invalidate();
UpdateWindow();
EndWaitCursor();
}
void CNewCloudView::OnSin3()
{
// TODO: Add your command handler code here
CNewCloudDoc* pDoc = GetDocument();
pDoc->flag=3;
pDoc->Sflag=3;
CSinDlg dlg;
float Ex,En,He;
if(dlg.DoModal()!=IDOK)
{
return;
}
En=dlg.m_En;
He=dlg.m_He;
Ex=dlg.m_Ex;
BeginWaitCursor();
SinCloudGenerator(Ex, En, He);
// Draw=TRUE;
Invalidate();
UpdateWindow();
EndWaitCursor();
}
void CNewCloudView::OnCos1()
{
// TODO: Add your command handler code here
CNewCloudDoc* pDoc = GetDocument();
pDoc->flag=4;
pDoc->Sflag=1;
CSinDlg dlg;
float Ex,En,He;
if(dlg.DoModal()!=IDOK)
{
return;
}
En=dlg.m_En;
He=dlg.m_He;
Ex=dlg.m_Ex;
BeginWaitCursor();
SinCloudGenerator(Ex, En, He);
// Draw=TRUE;
Invalidate();
UpdateWindow();
EndWaitCursor();
}
void CNewCloudView::OnCos2()
{
// TODO: Add your command handler code here
CNewCloudDoc* pDoc = GetDocument();
pDoc->flag=4;
pDoc->Sflag=2;
CSinDlg dlg;
float Ex,En,He;
if(dlg.DoModal()!=IDOK)
{
return;
}
En=dlg.m_En;
He=dlg.m_He;
Ex=dlg.m_Ex;
BeginWaitCursor();
SinCloudGenerator(Ex, En, He);
// Draw=TRUE;
Invalidate();
UpdateWindow();
EndWaitCursor();
}
void CNewCloudView::OnCos3()
{
// TODO: Add your command handler code here
CNewCloudDoc* pDoc = GetDocument();
pDoc->flag=4;
pDoc->Sflag=3;
CSinDlg dlg;
float Ex,En,He;
if(dlg.DoModal()!=IDOK)
{
return;
}
En=dlg.m_En;
He=dlg.m_He;
Ex=dlg.m_Ex;
BeginWaitCursor();
SinCloudGenerator(Ex, En, He);
// Draw=TRUE;
Invalidate();
UpdateWindow();
EndWaitCursor();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -