Mandelbrot set: Difference between revisions
Content added Content deleted
(New page: {{Wikipedia|Mandelbrot_set|de}} Category:Recursion{{task|Fractals}}Generate and draw the mandelbrot set fractal. =={{header|C}}== {{works with|gcc}} <lang C> #d...) |
No edit summary |
||
Line 1: | Line 1: | ||
{{Wikipedia|Mandelbrot_set|de}} |
{{Wikipedia|Mandelbrot_set|de}} |
||
[[Category:Recursion]]{{task|Fractals}}Generate and draw the [[wp: |
[[Category:Recursion]]{{task|Fractals}}Generate and draw the [[wp:Mandelbrot set|Mandelbrot set]]. |
||
=={{header|C}}== |
=={{header|C}}== |
Revision as of 05:08, 31 March 2009
This page uses content from Wikipedia. The original article was at Mandelbrot_set. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) |
Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Generate and draw the Mandelbrot set.
C
<lang C>
- define MAX_ITERATIONS 500
void draw(int width, int height){
int x, y, colour; double x0, y0, xtemp, cr, ci;
for (x = 0; x < width, x++){ for (y = 0; y < height; y++){ x0 = y0 = 0; cr = ((double)x / (double)width - 0.5); ci = ((double)y / (double)height - 0.5); i = 0;
while (x0*x0 + y0*y0 <= 4.0 && i < MAX_ITERATIONS){ xtemp = x0*x0 - y0*y0 + cr; y0 = 2*x0*0 + ci; x0 = xtemp; i++; }
colour = (i == MAX_ITERATIONS ? 1 : 0);
DrawPixel(x, y, colour, colour, colour); } }
} </lang>