c语言分形图程序,win32_c语言绘制曼德博集合(分形绘制)

//曼德博集合.cpp : Defines the entry point for the application.//#include"stdafx.h"#include"resource.h"#include

#define MAX_LOADSTRING 100

//Global Variables:

HINSTANCE hInst; //current instance

TCHAR szTitle[MAX_LOADSTRING]; //The title bar text

TCHAR szWindowClass[MAX_LOADSTRING]; //The title bar text

const int iXmax = 600;const int iYmax = 600;const double CxMin = -2.5;const double CxMax = 1.5;const double CyMin = -2.0;const double CyMax = 2.0;const int IterationMax = 200;const double EscapeRadius = 2;//Foward declarations of functions included in this code module:

ATOM MyRegisterClass(HINSTANCE hInstance);

BOOL InitInstance(HINSTANCE,int);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);intAPIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,intnCmdShow)

{//TODO: Place code here.

MSG msg;

HACCEL hAccelTable;//Initialize global strings

LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING);

MyRegisterClass(hInstance);//Perform application initialization:

if (!InitInstance (hInstance, nCmdShow))

{returnFALSE;

}

hAccelTable=LoadAccelerators(hInstance, (LPCTSTR)IDC_MY);//Main message loop:

while (GetMessage(&msg, NULL, 0, 0))

{if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}returnmsg.wParam;

}//

//FUNCTION: MyRegisterClass()//

//PURPOSE: Registers the window class.//

//COMMENTS://

//This function and its usage is only necessary if you want this code//to be compatible with Win32 systems prior to the 'RegisterClassEx'//function that was added to Windows 95. It is important to call this function//so that the application will get 'well formed' small icons associated//with it.//ATOM MyRegisterClass(HINSTANCE hInstance)

{

WNDCLASSEX wcex;

wcex.cbSize= sizeof(WNDCLASSEX);

wcex.style= CS_HREDRAW |CS_VREDRAW;

wcex.lpfnWndProc=(WNDPROC)WndProc;

wcex.cbClsExtra= 0;

wcex.cbWndExtra= 0;

wcex.hInstance=hInstance;

wcex.hIcon=LoadIcon(hInstance, (LPCTSTR)IDI_MY);

wcex.hCursor=LoadCursor(NULL, IDC_ARROW);

wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);

wcex.lpszMenuName=(LPCSTR)IDC_MY;

wcex.lpszClassName=szWindowClass;

wcex.hIconSm=LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);return RegisterClassEx(&wcex);

}//

//FUNCTION: InitInstance(HANDLE, int)//

//PURPOSE: Saves instance handle and creates main window//

//COMMENTS://

//In this function, we save the instance handle in a global variable and//create and display the main program window.//BOOL InitInstance(HINSTANCE hInstance, intnCmdShow)

{

HWND hWnd;

hInst= hInstance; //Store instance handle in our global variable

hWnd=CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT,0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);if (!hWnd)

{returnFALSE;

}

ShowWindow(hWnd, nCmdShow);

UpdateWindow(hWnd);returnTRUE;

}//

//FUNCTION: WndProc(HWND, unsigned, WORD, LONG)//

//PURPOSE: Processes messages for the main window.//

//WM_COMMAND - process the application menu//WM_PAINT - Paint the main window//WM_DESTROY - post a quit message and return//

//LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{intwmId, wmEvent;

PAINTSTRUCT ps;

HDC hdc;

TCHAR szHello[MAX_LOADSTRING];

LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);switch(message)

{caseWM_COMMAND:

wmId=LOWORD(wParam);

wmEvent=HIWORD(wParam);//Parse the menu selections:

switch(wmId)

{caseIDM_ABOUT:

DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);break;caseIDM_EXIT:

DestroyWindow(hWnd);break;default:returnDefWindowProc(hWnd, message, wParam, lParam);

}break;caseWM_PAINT:

{//添加大括号,使内部的变量初始化赋值编译经过

hdc = BeginPaint(hWnd, &ps);//TODO: Add any drawing code here...

intiX,iY;doubleCx,Cy;double PixelWidth = (CxMax - CxMin)/iXmax;doublePixelHeight;

PixelHeight= (CyMax - CyMin)/iYmax;

COLORREF color;doubleZx,Zy;doubleZx2,Zy2;

INT Iteration;doubleER2;

ER2= EscapeRadius *EscapeRadius;//依据曼德博集合计算原理,获取每一个像素的属性

for(iY = 0;iY < iYmax;iY++)//循环每一行

{

Cy= CyMin + iY*PixelHeight;if(fabs(Cy) < PixelHeight/2)

Cy= 0.0;for(iX=0;iX < iXmax;iX++)//循环每一列

{

Cx= CxMin +iX*PixelHeight;

Zx= Zy= Zy2=Zx2 = 0.0;

Iteration= 0;//针对每一个像素进行循环计算

while(Iteration < IterationMax && ((Zx2 + Zy2)

{

Zy= 2* Zx*Zy +Cy;

Zx= Zx2 - Zy2 +Cx;

Zx2= Zx*Zx;

Zy2= Zy *Zy;

Iteration++;

}if(Iteration ==IterationMax)

color= RGB(0,0,0);//前景色黑色

elsecolor= RGB(255,255,255);//背景色白色

SetPixel(hdc,iX,iY,color);

}

}//RECT rt;//GetClientRect(hWnd, &rt);//DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);

EndPaint(hWnd,&ps);break;

}caseWM_DESTROY:

PostQuitMessage(0);break;default:returnDefWindowProc(hWnd, message, wParam, lParam);

}return 0;

}//Mesage handler for about box.

LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

{switch(message)

{caseWM_INITDIALOG:returnTRUE;caseWM_COMMAND:if (LOWORD(wParam) == IDOK || LOWORD(wParam) ==IDCANCEL)

{

EndDialog(hDlg, LOWORD(wParam));returnTRUE;

}break;

}returnFALSE;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以帮你回答这个问题。不过需要说明的是,我是一名语言模型,无法直接进行绘操作。但是我可以为你提供绘制勃罗分的代码示例,你可以在计算机上运行该代码并生成分像。 绘制勃罗分程序示例: ```python import numpy as np import matplotlib.pyplot as plt # 定义计算勃罗分的函数 def mandelbrot(c, maxiter): z = c for n in range(maxiter): if abs(z) > 2: return n z = z*z + c return 0 # 定义绘制的函数 def mandelbrot_plot(xmin, xmax, ymin, ymax, width, height, maxiter): r1 = np.linspace(xmin, xmax, width) r2 = np.linspace(ymin, ymax, height) A, B = np.meshgrid(r1, r2) C = A + B*1j img = np.zeros((height, width)) for i in range(width): for j in range(height): img[j, i] = mandelbrot(C[j, i], maxiter) plt.imshow(img, cmap='hot', extent=[xmin, xmax, ymin, ymax]) plt.show() # 调用绘制的函数 mandelbrot_plot(-2.0, 0.5, -1.25, 1.25, 1000, 1000, 80) ``` 这段代码使用 Python 语言编写,利用 Numpy 和 Matplotlib 库实现了勃罗分绘制。具体来说,程序先定义了一个计算勃罗分的函数 mandelbrot,该函数接受一个复数 c 和最大迭代次数 maxiter 作为输入,输出勃罗分上点 (c.real, c.imag) 的颜色值。接着,程序定义了一个绘制的函数 mandelbrot_plot,该函数接受六个参数:分的 x、y 轴范围、分辨率、最大迭代次数。该函数调用了前面定义的计算勃罗分的函数 mandelbrot,将计算结果转换为像,并使用 Matplotlib 库绘制出来。 最后,程序调用了绘制的函数 mandelbrot_plot,传入了所需的参数,生成分像并显示在屏幕上。 注意:该示例代码仅为演示用途,实际运行时可能需要根据具体情况进行修改和调整。另外,生成分像可能需要较长时间,建议在计算能力较强的计算机上运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值