Beginning of objective API rework
[xiph/unicode.git] / sushivision / example_fractal.c
blob43ed3fbe40a954900c22a6d0fabba49e298ca34e
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_func_t *f = sv_func_new(0, 2, fractal_objective, 0);
83 sv_obj_new("outer",
84 (sv_func_t *[]){f},
85 (int []){0},
86 "Y");
87 sv_obj_make_scale("0, .001, .01, .1, 1.0");
89 sv_obj_new("inner",
90 (sv_func_t *[]){f},
91 (int []){1},
92 "Y");
93 sv_obj_make_scale("0, .001, .01, .1, 1.0");
95 sv_panel_new_2d(0,"Mandel/Julia Fractal",
96 "inner, outer",
97 "rc,ic,rz,iz,it",
98 0);
100 sv_go();
101 sv_join();
103 return 0;