openGPMP
Open Source Mathematics Package
Macros | Functions
Mandelbrot.cpp File Reference
#include <GL/glut.h>
#include <graphics.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define MAXCOUNT   100
 

Functions

void fractal (float left, float top, float xside, float yside)
 
int main ()
 

Macro Definition Documentation

◆ MAXCOUNT

#define MAXCOUNT   100

Definition at line 39 of file Mandelbrot.cpp.

Function Documentation

◆ fractal()

void fractal ( float  left,
float  top,
float  xside,
float  yside 
)

Definition at line 42 of file Mandelbrot.cpp.

42  {
43  float xscale, yscale, zx, zy, cx, tempx, cy;
44  int x, y, i, j;
45  int maxx, maxy, count;
46 
47  // getting maximum value of x-axis of screen
48  maxx = getmaxx();
49 
50  // getting maximum value of y-axis of screen
51  maxy = getmaxy();
52 
53  // setting up the xscale and yscale
54  xscale = xside / maxx;
55  yscale = yside / maxy;
56 
57  // calling rectangle function
58  // where required image will be seen
59  rectangle(0, 0, maxx, maxy);
60 
61  // scanning every point in that rectangular area.
62  // Each point represents a Complex number (x + yi).
63  // Iterate that complex number
64  for (y = 1; y <= maxy - 1; y++) {
65  for (x = 1; x <= maxx - 1; x++) {
66  // c_real
67  cx = x * xscale + left;
68 
69  // c_imaginary
70  cy = y * yscale + top;
71 
72  // z_real
73  zx = 0;
74 
75  // z_imaginary
76  zy = 0;
77  count = 0;
78 
79  // Calculate whether c(c_real + c_imaginary) belongs
80  // to the Mandelbrot set or not and draw a pixel
81  // at coordinates (x, y) accordingly
82  // If you reach the Maximum number of iterations
83  // and If the distance from the origin is
84  // greater than 2 exit the loop
85  while ((zx * zx + zy * zy < 4) && (count < MAXCOUNT)) {
86  // Calculate Mandelbrot function
87  // z = z*z + c where z is a complex number
88 
89  // tempx = z_real*_real - z_imaginary*z_imaginary +
90  // c_real
91  tempx = zx * zx - zy * zy + cx;
92 
93  // 2*z_real*z_imaginary + c_imaginary
94  zy = 2 * zx * zy + cy;
95 
96  // Updating z_real = tempx
97  zx = tempx;
98 
99  // Increment count
100  count = count + 1;
101  }
102 
103  // To display the created fractal
104  putpixel(x, y, count);
105  }
106  }
107 }
#define MAXCOUNT
Definition: Mandelbrot.cpp:39

References MAXCOUNT.

Referenced by main().

◆ main()

int main ( void  )

Definition at line 110 of file Mandelbrot.cpp.

110  {
111  // gm is Graphics mode which is
112  // a computer display mode that
113  // generates image using pixels.
114  // DETECT is a macro defined in
115  // "graphics.h" header file
116  int gd = DETECT, gm, errorcode;
117 
118  float left, top, xside, yside;
119 
120  // setting the left, top, xside and yside
121  // for the screen and image to be displayed
122 
123  /*
124  left = -1;
125  top = 0;
126  xside = 0;
127  yside = 0.2;
128  */
129  left = -1.74;
130  top = -0.25;
131  xside = 0.25;
132  yside = 0.45;
133 
134  char driver[] = "";
135 
136  // initgraph initializes the
137  // graphics system by loading a
138  // graphics driver from disk
139  initgraph(&gd, &gm, driver);
140 
141  // Function calling
142  fractal(left, top, xside, yside);
143 
144  getch();
145 
146  // closegraph function closes the
147  // graphics mode and deallocates
148  // all memory allocated by
149  // graphics system
150  closegraph();
151 
152  return 0;
153 }
void fractal(float left, float top, float xside, float yside)
Definition: Mandelbrot.cpp:42

References fractal().