Broad front of work in progress:
[xiph/unicode.git] / sushivision / example_fractal.c
blob2f6120671e553bdea066fa4b3c3f6499aa877702
1 /*
3 * sushivision copyright (C) 2006-2007 Monty <monty@xiph.org>
5 * sushivision is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * sushivision is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with sushivision; see the file COPYING. If not, write to the
17 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define _GNU_SOURCE
23 #include <stdio.h>
24 #include <math.h>
25 #include "sushivision.h"
27 static void fractal_objective(double *d, double *ret){
28 int max_iter = d[4];
29 int i;
30 double z, zi, zz;
31 double c=d[0],ci=d[1];
33 ret[0]=NAN;
34 ret[1]=1.;
36 z = d[2]; zi = d[3];
37 for(i=0;i<max_iter;i++){
38 zz = z*z - zi*zi + c;
39 zi = 2.0*z*zi + ci;
40 z = zz;
41 if (z*z + zi*zi > 4.0){
42 ret[0] = (double)i/max_iter;
43 ret[1] = NAN;
44 return;
48 ret[1] = sqrt(z*z + zi*zi)/4.;
51 int main(int argc, char *argv[]){
53 // before any gtk, gdk or glib setup
54 sv_init();
56 //g_thread_init (NULL);
57 //gtk_init (&argc, &argv);
58 //gdk_threads_init ();
60 // "name:label(arg,arg,arg...)"
62 sv_dim_new("rc:Re\\(c\\)");
63 sv_dim_make_scale("-2.25, -0.75, 0, 0.25, 0.75");
65 sv_dim_new("ic:Im\\(c\\)");
66 sv_dim_make_scale("-2,-1,0,1,2");
68 sv_dim_new("rz:Re\\(z0\\)");
69 sv_dim_make_scale("-2.25, -1, 0, 1, 2.25");
71 sv_dim_new("iz:Im\\(z0\\)");
72 sv_dim_make_scale("-2.25, -1, 0, 1, 2.25");
74 sv_dim_new("it:Max Iterations(picklist)");
75 sv_dim_make_scale("100:one hundred,"
76 "1000:one thousand,"
77 "10000:ten thousand,"
78 "100000:one hundred thousand");
79 sv_dim_set_value(100);
81 sv_obj_new("outer",fractal_objective,"rc,ic,rz,iz,it", "Z,*");
82 sv_obj_make_scale("0, .001, .01, .1, 1.0");
84 sv_obj_new("inner",fractal_objective,"rc,ic,rz,iz,it", "*,Z");
85 sv_obj_make_scale("0, .001, .01, .1, 1.0");
87 sv_panel_new_2d(0,"Mandel/Julia Fractal",
88 "inner, outer",
89 "rc(X,Y), ic(X,Y), rz(X,Y), iz(X,Y), it",
90 0);
92 sv_go();
93 sv_join();
95 return 0;