混沌特性的演示_第1頁
混沌特性的演示_第2頁
混沌特性的演示_第3頁
混沌特性的演示_第4頁
混沌特性的演示_第5頁
已閱讀5頁,還剩8頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、用VC6.0建一個對話框窗體,命名為Chaos在ChaosDlg.cpp文件下:BOOL CChaosDlg:OnInitDialog()CDialog:OnInitDialog();MoveWindow(0,0,1024,768,true);/ Add "About." menu item to system menu./ IDM_ABOUTBOX must be in the system command range.ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0x

2、F000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL)CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ Set the icon for this dialog. The framework d

3、oes this automatically/ when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small icon/角度的分界線tan_1=tan(60*pi/180.0); tan_2=tan(120*pi/180.0); tan_3=tan(240*pi/180.0); tan_4=tan(300*pi/180.0);return TRUE; / return TRUE unless you se

4、t the focus to a controlvoid CChaosDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialog:OnSysCommand(nID, lParam);/ If you add a minimize button to your dialog, you will need the code below/ to draw the icon. For MFC applicat

5、ions using the document/view model,/ this is automatically done for you by the framework.void CChaosDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint cxIcon = GetSystemMetrics(S

6、M_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;/ Draw the icondc.DrawIcon(x, y, m_hIcon);elseCDialog:OnPaint();/*將作圖區(qū)域底色設為白色*/CRect rec;rec.left=0;rec.top=0;rec.right=767;rec.bott

7、om=767;CDC *dc;dc=this->GetDC();CBrush hbr;hbr.CreateSolidBrush(RGB(255,255,255);dc->FillRect(&rec,&hbr);/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CChaosDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;void CChaosDlg:OnOK()

8、/ TODO: Add extra validation hereUpdateData(TRUE);CDC *dc;dc=this->GetDC();double x0,y0,x1,y1,dx,dy;int col,row,color;/繪圖范圍是-2,2/dx=dy=4.0/767.0;for(col=0;col<=767;col+)for(row=0;row<=767;row+) x0=(double)col*dx-2;y0=(double)row*dy-2;color=judge_color_point(x0,y0);dc->SetPixel(col,767-ro

9、w,colorlistcolor);dc->MoveTo(20-1,20-1);dc->LineTo(747+1,20-1);dc->LineTo(747+1,747+1);dc->LineTo(20-1,747+1);dc->LineTo(20-1,20-1);/畫出圖形/for(col=20;col<=747;col+)for(row=20;row<=747;row+)x0=(double)(col*dx-2);/-1.0;y0=(double)(row*dy-2);/-1.0;x1=itearate_fre(x0,y0,this->m_ed

10、it1);y1=itearate_fim(x0,y0,this->m_edit1);color=judge_color_point(x1,y1);dc->SetPixel(col,767-row,colorlistcolor);x0=x1;y0=y1;UpdateData(FALSE);int CChaosDlg:judge_color_point(double x, double y)int z1;double division;if(x>0&&y>0)division=y/x;if(division<=tan_1)z1=1;elsez1=2;i

11、f(x<0&&y>=0)division=y/x;if(division<=tan_2)z1=2;elsez1=3;if(x<0&&y<0)division=y/x;if(division<=tan_3)z1=4;elsez1=5;if(x>0&&y<=0)division=y/x; if(division<=tan_4)z1=5;elsez1=0;/x坐標軸的判斷if(x=0&&y>0)z1=2;if(x=0&&y<=0)z1=5;return(z

12、1);double CChaosDlg:fre(double x, double y)double z;z=2.5*x*(1-x*x-y*y)+0.9*(x*x-y*y);return(z);double CChaosDlg:fim(double x, double y)double z;z=-1.8*x*y+2.5*y*(1-x*x-y*y);return(z);double CChaosDlg:itearate_fre(double x, double y, int n)int i;double z;double xnew,ynew;for(i=0;i<n;i+) xnew=fre(

13、x,y);ynew=fim(x,y);x=xnew;y=ynew;z=x;return(z);double CChaosDlg:itearate_fim(double x, double y, int n)int i;double z;double xnew,ynew;for(i=0;i<n;i+) xnew=fre(x,y);ynew=fim(x,y);x=xnew;y=ynew;z=y;return(z);/存圖void CChaosDlg:OnSave() int x1,x2,y1,y2;int i,j,flag;BYTE r,g,b;COLORREF clr;CClientDC

14、dc(this);flag = 0;for(i = 0;i < 768;i+)for(j = 0;j < 768;j+)clr = dc.GetPixel(i,j);r = GetRValue(clr);g = GetGValue(clr);b = GetBValue(clr);if(r != 255 | g != 255 | b != 255)flag = 1;x1 = i;break;if(flag)break;flag = 0;for(i = 767;i >=0;i-)for(j = 767;j >=0;j-)clr = dc.GetPixel(i, j);r =

15、 GetRValue(clr);g = GetGValue(clr);b = GetBValue(clr);if(r != 255 | g != 255 | b != 255)flag = 1;x2 = i;break;if(flag)break;flag = 0;for(j = 0;j < 768;j+)for(i = x1;i <= x2;i+)clr = dc.GetPixel(i, j);r = GetRValue(clr);g = GetGValue(clr);b = GetBValue(clr);if(r != 255 | g != 255 | b != 255)fla

16、g = 1;y1 = j;break;if(flag)break;flag = 0;for(j = 767;j >=0;j-)for(i = x2;i >=x1;i-)clr = dc.GetPixel(i, j);r = GetRValue(clr);g = GetGValue(clr);b = GetBValue(clr);if(r != 255 | g != 255 | b != 255)flag = 1;y2 = j;break;if(flag)break;/保存圖片CRectrect;rect.SetRect(x1,y1,x2,y2);/CClientDCdc(this)

17、; CDC memDC;/CRectrect;memDC.CreateCompatibleDC(&dc);CBitmap bm;int Width = 768;int Height = 768;bm.CreateCompatibleBitmap(&dc, Width, Height);CBitmap* pOld = memDC.SelectObject(&bm);memDC.BitBlt(0, 0, Width, Height, &dc, 0, 0, SRCCOPY);memDC.SelectObject(pOld);BITMAP btm;bm.GetBitma

18、p(&btm);DWORD size = btm.bmWidthBytes * btm.bmHeight;LPSTR lpData = (LPSTR)GlobalAllocPtr(GPTR, size);BITMAPFILEHEADER bfh;/BITMAPINFOHEADER bih;bih.biBitCount = btm.bmBitsPixel;bih.biClrImportant = 0;bih.biClrUsed = 0;bih.biCompression = 0;bih.biHeight = btm.bmHeight;bih.biPlanes = 1;bih.biSize

19、 = sizeof(BITMAPINFOHEADER);bih.biSizeImage = size;bih.biWidth = btm.bmWidth;bih.biXPelsPerMeter = 0;bih.biYPelsPerMeter = 0;GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);/bm.GetBitmapBits(size,lpData);/此函數(shù)在處理5-5-5模式的16位色下會出現(xiàn)顏色混亂bfh.bfReserved1 = bfh.bfReserved2 = 0;bfh

20、.bfType = (WORD)('M'<< 8)|'B');bfh.bfSize = 54 + size;bfh.bfOffBits = 54;CFileDialog dlg(false,_T("BMP"),_T("*.bmp"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("*.bmp|*.bmp|*.*|*.*|");if (dlg.DoModal()!=IDOK)return;CFile bf;CString ss=dlg.GetPathNam

21、e();if(bf.Open(ss, CFile:modeCreate | CFile:modeWrite)bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER);bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER);bf.WriteHuge(lpData, size);bf.Close();AfxMessageBox("保存成功");GlobalFreePtr(lpData);void CChaosDlg:OnButton1() / TODO: Add your control notification handler code hereCRect rec;rec.left=0;rec.top=0;rec.right=768;rec.bottom=767;CDC *dc;dc=this->GetDC();CBrush hbr;hbr.CreateSolidBrush(RGB(255,255,255);dc->FillRect(&rec,&hbr);/double x0=-0.5,y0=0.5,x1,y1,dx,dy;dx=dy=4.0/767

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論