i want draw mandelbrot ppm file in c. code working drawing black. have code wikia. key success think "alfa" (i think so). have no idea alfa should be. here's code:
#include <stdio.h> #include <stdlib.h> #define w 800 #define h 800 //rgb struct struct rgb { int r; int g; int b; }; struct rgb picture[w][h]; void draw() { int i, j, iteration, max_iteration, alfa, color; float x, y, x0, y0, xtemp; for(i=0;i<w;++i) { for(j=0;j<h;++j) { x0 = 1; //scaled x (e.g interval(-2.5, 1)) y0 = -1; //scaled y (e.g interval(-1, 1)) x = 0.0; y = 0.0; iteration = 0; max_iteration = 1000; while (x*x + y*y < 2*2 && iteration < max_iteration) { xtemp = x*x - y*y + x0; y = 2*x*y + y0; x = xtemp; iteration = iteration+ 1; alfa = x*y; //??? } color = alfa * (iteration / max_iteration); picture[i][j].r = color; picture[i][j].g = color; picture[i][j].b = color; } } } int main() { //variables int i,j; draw(); file *fp; fp = fopen("picture.ppm", "w"); fprintf(fp,"p3\n#test\n%d %d\n256\n", w, h); (i=0; < w; ++i) { (j=0; j < h; ++j) { fprintf(fp,"%d %d %d ", picture[i][j].r, picture[i][j].g , picture[i][j].b); } fprintf(fp, "\n"); } fclose(fp); return 0; }
in line
color = alfa * (iteration / max_iteration);
the divison iteration / max_iteration
int
division result 0
(possibly 1
if ever iteration == max_iteration
).
try working in float
, or rearrange this
color = alfa * iteration / max_iteration;
removing parentheses. you'll have watch out int
range isn't broken.
having said that, seems not sure alfa
is. suggest 255
grey-scale image.
Comments
Post a Comment