Google
Web alhem.net
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

mandel.cpp File Reference

#include <stdincl.h>
#include "Globals.h"
#include "mandel.h"

Include dependency graph for mandel.cpp:

Include dependency graph

Go to the source code of this file.

Defines

#define STOPLIM   40

Functions

int mandel_color (double x, double y)
void mandel_set ()


Define Documentation

#define STOPLIM   40
 

Referenced by mandel_color().


Function Documentation

int mandel_color double  x,
double  y
 

File ......... mandel.cpp Published .... 2005-02-07 Author ....... grymse@alhem.net

Definition at line 29 of file mandel.cpp.

References STOPLIM.

Referenced by Grid::GetXY().

00030 { 00031 double cx,cy; 00032 double limit; 00033 double ax,ay; 00034 double a1,b1; 00035 double lp; 00036 double a2,b2; 00037 00038 cx = -0.3 + Globals::m_zx; 00039 cy = -0.66 + Globals::m_zy; 00040 // Globals::m_scale = 0.002; 00041 limit = 4; 00042 00043 // {What is the * mathematical * value of this point?} 00044 ax = cx + (x) * Globals::m_scale; 00045 ay = cy + (y) * Globals::m_scale; 00046 00047 // {And now for the magic formula!} 00048 a1 = ax; 00049 b1 = ay; 00050 lp = 0; 00051 #define STOPLIM 40 00052 do 00053 { 00054 // {Do one iteration.} 00055 lp = lp + 1; 00056 a2 = a1 * a1 - b1 * b1 + ax; 00057 b2 = 2 * a1 * b1 + ay; 00058 // {This is indeed the square of a + b1, done component-wise.} 00059 a1 = a2; 00060 b1 = b2; 00061 } while (!(lp > STOPLIM || ((a1 * a1) + (b1 * b1) > limit))); 00062 // {The first condition is satisfied if we have convergence. 00063 // The second is satisfied if we have divergence.} 00064 00065 // {Define colour and draw pixel.} 00066 if (lp > STOPLIM) 00067 { 00068 lp = STOPLIM; 00069 } 00070 // {If the point converges, it is part of the brot and we 00071 // draw it with colour 0, or black.} 00072 // pixel(x + 160,y + 100,lp); 00073 return (int)lp; 00074 }

void mandel_set  ) 
 

Definition at line 77 of file mandel.cpp.

00078 { 00079 double x,y; 00080 double cx,cy; 00081 double limit; 00082 double ax,ay; 00083 double a1,b1; 00084 double lp; 00085 double a2,b2; 00086 00087 // {Set up initial values for drawing. Try compiling the program 00088 // with different values here if you like!} 00089 cx = 0; 00090 00091 cy = 0; 00092 00093 // Globals::m_scale = 0.02; 00094 limit = 4; 00095 00096 // {Loop through all pixels on screen. For reasons that will become 00097 // clear, I am counting not from (0,0) but from (-160,-100).} 00098 for (x = -160; x < 160; x++) 00099 { 00100 for (y = -100; y <= 100; y++) 00101 { 00102 // {What is the * mathematical * value of this point?} 00103 ax = cx + x * Globals::m_scale; 00104 00105 ay = cy + y * Globals::m_scale; 00106 00107 // {And now for the magic formula!} 00108 a1 = ax; 00109 00110 b1 = ay; 00111 00112 lp = 0; 00113 do 00114 { 00115 // {Do one iteration.} 00116 lp = lp + 1; 00117 a2 = a1 * a1 - b1 * b1 + ax; 00118 b2 = 2 * a1 * b1 + ay; 00119 // {This is indeed the square of a + bi, done component-wise.} 00120 a1 = a2; 00121 00122 b1 = b2; 00123 } while (lp > 255 || ((a1 * a1) + (b1 * b1) > limit)); 00124 // {The first condition is satisfied if we have convergence. 00125 // The second is satisfied if we have divergence.} 00126 00127 // {Define colour and draw pixel.} 00128 if (lp > 255) 00129 { 00130 lp = 0; 00131 } 00132 // {If the point converges, it is part of the brot and we 00133 // draw it with colour 0, or black.} 00134 // pixel(x + 160,y + 100,lp); 00135 } 00136 00137 } // for (x) 00138 }


Generated for SDL C++ GUI by doxygen 1.3.6