曼德博洛特集C语言源代码.doc_第1页
曼德博洛特集C语言源代码.doc_第2页
曼德博洛特集C语言源代码.doc_第3页
曼德博洛特集C语言源代码.doc_第4页
曼德博洛特集C语言源代码.doc_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Ch04Ex06 class Program static void Main(string args) double realCoord, imagCoord; double realTemp, imagTemp, realTemp2,arg; int iterations;/ for (imagCoord = 1.2; imagCoord = -1.2; imagCoord -= 0.05) for (realCoord = -0.6; realCoord = 1.77; realCoord += 0.03) iterations = 0; realTemp = realCoord; imagTemp = imagCoord; arg = (realCoord * realCoord) + (imagCoord * imagCoord); while (arg 4) & (iterations 40) realTemp2 = (realTemp * realTemp) - (imagTemp * imagTemp) - realCoord; imagTemp = (2 * realTemp * imagTemp) - imagCoord; realTemp = realTemp2; arg = (realTemp * realTemp) + (imagTemp * imagTemp); iterations += 1; switch (iterations % 4) case 0: Console.Write(.); break; case 1: Console.Write(o); break; case 2: Console.Write(O); break; case 3: Console.Write(); break; Console.Write(n); Console.ReadKey(); / EasyX Visual C+ 6.0 #include #include / #define ITERATIONS 1000 / #define MAXCOLOR 64 / / / struct COMPLEX double re; double im;/ COMPLEX operator * (COMPLEX a, COMPLEX b) COMPLEX c; c.re = a.re * b.re - a.im * b.im; c.im = a.im * b.re + a.re * b.im; return c;/ COMPLEX operator + (COMPLEX a, COMPLEX b) COMPLEX c; c.re = a.re + b.re; c.im = a.im + b.im; return c;/ / int ColorMAXCOLOR;/ void InitColor() / HSL h1 h2 int h1 = 240, h2 = 30; for(int i=0; iMAXCOLOR/2; i+) Colori = HSLtoRGB(float)h1, 1.0f, i * 2.0f / MAXCOLOR); ColorMAXCOLOR-1-i = HSLtoRGB(float)h2, 1.0f, i * 2.0f / MAXCOLOR); / Mandelbrot Set ()/void Draw(double fromx, double fromy, double tox, double toy) COMPLEX z, c; for(int x=0; x640; x+) c.re = fromx + (tox - fromx) * (x / 640.0); for(int y=0; y480; y+) c.im = fromy + (toy - fromy) * (y / 480.0); z.re = z.im = 0; for(int k=0; k 4.0 ) break; z = z * z + c; putpixel(x, y, (k = ITERATIONS) ? 0 : Colork % MAXCOLOR); / /void main() / initgraph(640, 480); InitColor(); / Mandelbrot Set() double fromx, fromy, tox, toy; fromx = -2.1; tox = 1.1; fromy = -1.2; toy = 1.2; Draw(fromx, fromy, tox, toy); / MOUSEMSG m; bool isLDown = false; int selfx, selfy, seltx, selty; / while(!kbhit() m = GetMouseMsg(); / switch(m.uMsg) / case WM_MBUTTONUP: fromx = -2.1; tox = 1.1; fromy = -1.2; toy = 1.2; Draw(fromx, fromy, tox, toy); break; / case WM_MOUSEMOVE: if (isLDown) rectangle(selfx, selfy, seltx, selty); seltx = m.x; selty = m.y; rectangle(selfx, selfy, seltx, selty); break; / case WM_LBUTTONDOWN: setcolor(WHITE); setwritemode(R2_XORPEN); isLDown = true; selfx = seltx = m.x; selfy = selty = m.y; rectangle(selfx, selfy, seltx, selty); break; / case WM_LBUTTONUP: rectangle(selfx, selfy, seltx, selty); setwritemode(R2_COPYPEN); isLDown = false; seltx = m.x; selty = m.y; if (selfx = seltx | selfy = selty) break; / 4:3 int tmp; if (selfx seltx) tmp = selfx; selfx = seltx; seltx = tmp; if (selfy selty) tmp = selfy; selfy = selty; selty = tmp; if ( (seltx - selfx) * 0.75 (selty - selfy) ) selty += (3 - (selty - selfy) % 3); selfx -= (selty - selfy) / 3 * 4 / 2 - (seltx - selfx) / 2; seltx = selfx + (selty - selfy) / 3 * 4; else seltx += (4 - (seltx - selfx) % 4); selfy -= (seltx - selfx) * 3 / 4 / 2 - (selty - selfy ) / 2; selty = selfy + (seltx - selfx ) * 3 / 4; / double f, t; f = fromx + (tox - fromx) * selfx / 640; t = fromx + (tox - fromx) * seltx / 640; fromx = f

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论