【正文】
如果 b 有一個輕微的減小 , 比如 , 那么軌跡會收縮至奇異吸引子 (The attractor points)。 下面是繪制 GumowskiMira 分形圖的算法: ○ 1 假定 a=, b=, i=0, x=1, y=1。x = b * y + w 。y = w z 。 ○ 3 如果 i1000, 對點 (x*20,y*20)著色,返回步驟 ○ 2 。 圖形參見:圖 。 理學學士學位論文 第二章 分形 相關 理 論 問題 12 ○ 1 獲取文件名可以使用 CFileDialog 類,初始化 CFileDialog 類后,使用類成員函數(shù) DoModal()顯示對話框。 ○ 2 將當前客戶區(qū)域拷貝為位圖操作比較復雜,這里只能將其簡略化后再加以描述。得到。得到,函數(shù)中的參數(shù) lpRect 表示客戶區(qū)域的大小。在函數(shù)中,因為這里要將客戶區(qū)坐標轉換為屏幕坐標 (如欲深入了解,請參見《 Windows 編程》第五章 圖形基礎 ),所以要先用函數(shù) void ClientToScreen( LPRECT lpRect ) const 將顯示區(qū)域坐標轉換為屏幕坐標??梢赃_到要求。 ○ 3 將位圖保存到磁盤,這個操作比較簡單,創(chuàng)建一個使用用戶輸入的文件名的文件,然后將圖形寫入文件即可。位圖的復制和剪切原理是相同的,它們不同點在于剪切的時候需要在將選定區(qū)域復制后將其重畫為白色區(qū)域。 3, 位圖的粘貼,使用 BitBlt()函數(shù)就可以實現(xiàn)。 if(()==IDOK) { CRect NowRect。NowRect)。 (hDib,())。 // handle to DIB // check for a valid window handle if (!hWnd) return NULL。 // convert client coords to screen coords = lpRectleft。 = lpRectright。 ClientToScreen(hWnd, amp。 ClientToScreen(hWnd, amp。 lpRectleft = 。 lpRectright = 。 // get the DIB of the client area by calling // CopyScreenToDIB and passing it the client rect hDIB = CopyScreenToDIB(lpRect)。 } 理學學士學位論文 第二章 分形 相關 理 論 問題 14 HDIB CGlobal::CopyScreenToDIB(LPRECT lpRect) { HBITMAP hBitmap。 // handle to palette HDIB hDIB = NULL。 // check for a valid bitmap handle if (!hBitmap) return NULL。 // convert the bitmap to a DIB hDIB = BitmapToDIB(hBitmap, hPalette)。 DeleteObject(hBitmap)。 } HBITMAP CGlobal::CopyScreenToBitmap(LPRECT lpRect) { HDC hScrDC, hMemDC。 // handles to deicedependent bitmaps int nX, nY, nX2, nY2。 // DIB width and height int xScrn, yScrn。 if (IsRectEmpty(lpRect)) return NULL。 hMemDC = CreateCompatibleDC(hScrDC)。 nY = lpRecttop。 nY2 = lpRectbottom。 yScrn = GetDeviceCaps(hScrDC, VERTRES)。 if (nY 0) nY = 0。 if (nY2 yScrn) nY2 = yScrn。 nHeight = nY2 nY。 // select new bitmap into memory DC hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap)。 // select old bitmap back into memory DC and get handle to // bitmap of the screen hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap)。 DeleteDC(hMemDC)。 } 位圖格式轉換函數(shù): HDIB CGlobal::BitmapToDIB(HBITMAP hBitmap, HPALETTE hPal) { BITMAP bm。 // bitmap header LPBITMAPINFOHEADER lpbi。 // size of memory block HANDLE hDIB, h。 // handle to DC WORD biBits。 // fill in BITMAP structure, return NULL if it didn39。bm)) return NULL。 // calculate bits per pixel 理學學士學位論文 第二章 分形 相關 理 論 問題 17 biBits = * 。 else if (biBits = 4) biBits = 4。 else // if greater than 8bit, force to 24bit biBits = 24。 = 。 = 1。 = BI_RGB。 = 0。 = 0。 // calculate size of memory block required to store BITMAPINFO dwLen = + PaletteSize((LPBYTE)amp。 // get a DC hDC = GetDC(NULL)。 RealizePalette(hDC)。 理學學士學位論文 第二章 分形 相關 理 論 問題 18 // if we couldn39。 RealizePalette(hDC)。 return NULL。 /// use our bitmap info. to fill BITMAPINFOHEADER *lpbi = bi。 // get the info. returned by GetDIBits and unlock memory block bi = *lpbi。 // if the driver did not fill in the biSizeImage field, make one up if ( == 0) = WIDTHBYTES((DWORD) * biBits) * 。bi) + 。 else { 理學學士學位論文 第二章 分形 相關 理 論 問題 19 // clean up and return NULL GlobalFree(hDIB)。 SelectPalette(hDC, hPal, TRUE)。 ReleaseDC(NULL, hDC)。 } // lock memory block and get pointer to it */ lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB)。 hDIB = NULL。 RealizePalette(hDC)。 return NULL。 // clean up GlobalUnlock(hDIB)。 RealizePalette(hDC)。 理學學士學位論文 第二章 分形 相關 理 論 問題 20 // return handle to the DIB return hDIB。 // Header for Bitmap file LPBITMAPINFOHEADER lpBI。 // file handle for opened file DWORD dwDIBSize。 if (!hDib) return FALSE。 if (fh == INVALID_HANDLE_VALUE) return FALSE。 if (!lpBI) { CloseHandle(fh)。 } // Check to see if we39。t // save it because our functions aren39。 CloseHandle(fh)。 } // Fill in the fields of the file header // Fill in file type (first 2 bytes must be BM for a bitmap) = DIB_HEADER_MARKER。 // Now calculate the size of the image // It39。t calculate size, so trust the biSizeImage // field if ((lpBIbiCompression == BI_RLE8) || (lpBIbiCompression == BI_RLE4)) dwDIBSize += lpBIbiSizeImage。 // Size of Bitmap Bits only // It39。 dwDIBSize += dwBmBitsSize。t we // fill in the biSizeImage field (this will fix any .BMP files which // have this field incorrect). lpBIbiSizeImage = dwBmBitsSize。 = 0。 理學學士學位論文 第二章 分形 相關 理 論 問題 22 // Now, calculate the offset the actual bitmap bits will be in // the file It39。 // Write the file header WriteFile(fh,(LPBYTE)amp。dwWritten, NULL)。dwWritten, NULL)。 CloseHandle(fh)。 // oops, something happened in the write else return TRUE。 程序概況 本程序共分為以下四個主菜單: 1, 文件:主要是有關文件的操作。 ○ 2 保存 : 保存當前圖片。 2, 查看:用于選定查看的分形圖形類型。 圖 ○ 2 Mandelbrot 集:查看 Mandelbrot