r4873 - trunk/misc
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sat Oct 25 10:31:32 EDT 2008
Author: div0
Date: 2008-10-25 10:31:32 -0400 (Sat, 25 Oct 2008)
New Revision: 4873
Modified:
trunk/misc/spherefunc2skybox.c
Log:
make a sample mandelbrot function
Modified: trunk/misc/spherefunc2skybox.c
===================================================================
--- trunk/misc/spherefunc2skybox.c 2008-10-25 13:44:11 UTC (rev 4872)
+++ trunk/misc/spherefunc2skybox.c 2008-10-25 14:31:32 UTC (rev 4873)
@@ -15,6 +15,33 @@
*b = 0.5 + 0.5 * z;
}
+#define MAXITER 4096
+double mandelbrot(double zx, double zy, double cx, double cy)
+{
+ double tmp;
+ int i;
+
+ for(i = 1; i < MAXITER; ++i)
+ {
+ tmp = zx;
+ zx = zx * zx - zy * zy + cx;
+ zy = 2 * tmp * zy + cy;
+ if(zx * zx + zy * zy > 4)
+ break;
+ }
+
+ return ((i - 1.0) * MAXITER) / (i * (MAXITER - 1.0));
+ // i.e. 0 for i=1, 1 for i=maxiter
+}
+
+void color_mandelbrot(double x, double y, double z, double *r, double *g, double *b)
+{
+ double iterations = mandelbrot(0, z*0.5, x - 1, y);
+ *r = pow(iterations, 100);
+ *g = pow(iterations, 25);
+ *b = pow(iterations, 10);
+}
+
void map_back(double x_in, double y_in, double *x_out, double *y_out, double *z_out)
{
*x_out = 2 * x_in - 1;
@@ -94,9 +121,9 @@
yyy /= r;
zzz /= r;
f(xxx, yyy, zzz, &rr, &gg, &bb);
- rgb[0] = floor(0.5 + rr * 255);
+ rgb[2] = floor(0.5 + rr * 255);
rgb[1] = floor(0.5 + gg * 255);
- rgb[2] = floor(0.5 + bb * 255);
+ rgb[0] = floor(0.5 + bb * 255);
fwrite(rgb, sizeof(rgb), 1, file);
}
@@ -118,6 +145,6 @@
{
if(argc != 2)
errx(1, "file name argument missing");
- map_all(argv[1], color_test);
+ map_all(argv[1], color_mandelbrot);
return 0;
}
More information about the nexuiz-commits
mailing list