Anonymous user
Mandelbrot set: Difference between revisions
→{{header|C}}: adapted code to use raster gfx ops tasks, fixed eye-jumped bugs, but running it I cant see the mandelbrot set, so needing review; hopefuly not my fault while fixing;)
(→{{header|C}}: A note about the C code, added C++) |
(→{{header|C}}: adapted code to use raster gfx ops tasks, fixed eye-jumped bugs, but running it I cant see the mandelbrot set, so needing review; hopefuly not my fault while fixing;)) |
||
Line 4:
=={{header|C}}==
{{
<lang C>▼
#define MAX_ITERATIONS 500▼
(The original code needed fixing; after fixing, it compiles and run, but to me it produced [http://i42.tinypic.com/122cls4.jpg this], not a Mandelbrot set as far as I can see)
void draw(int width, int height){▼
This code uses functions from category [[:Category:Raster graphics operations| Raster graphics operations]].
<lang c>#include <stdio.h>
#include "imglib.h"
▲#define MAX_ITERATIONS 500
void draw_mandel(image img){
unsigned int x, y;
color_component colour;
double x0, y0, xtemp, cr, ci;
unsigned int i;
width = img->width;
height = img->height;
for (x = 0; x < width
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*
x0 = xtemp;
i++;
}
/* points in the set are coloured as white, others are coloured black. */
colour = (i == MAX_ITERATIONS ? 255 : 0);
}
}
}
#define W 640
#define H 480
int main()
{
image img;
FILE *o;
img = alloc_img(W, H);
draw_mandel(img);
o = fopen("mandel.ppm", "w");
output_ppm(o, img);
fclose(o);
free_img(img);
=={{header|C++}}==
|