Commit numerous small fixups to discrete dimensions such that they
[xiph/unicode.git] / sushivision / example_fractal.c
blobbc8f211ca8ab808a916f3f6240190517bab9330d
1 /*
3 * sushivision copyright (C) 2006 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 sushiv_instance_t *s;
29 static void fractal_objective(double *d, double *ret){
30 int max_iter = d[4];
31 int i;
32 double z, zi, zz;
33 const double c=d[0],ci=d[1];
35 *ret=NAN;
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 = (double)i/max_iter;
43 return;
48 int sushiv_submain(int argc, char *argv[]){
50 s=sushiv_new_instance();
52 sushiv_new_dimension(s,0,"Re(c)",
53 5,(double []){-2.25,-0.75,0,0.25,0.75},
54 NULL,0);
55 sushiv_new_dimension(s,1,"Im(c)",
56 5,(double []){-2,-1,0,1,2},
57 NULL,0);
59 sushiv_new_dimension(s,2,"Re(z0)",
60 5,(double []){-2.25,-1,0,1,2.25},
61 NULL,0);
62 sushiv_new_dimension(s,3,"Im(z0)",
63 5,(double []){-2.25,-1,0,1,2.25},
64 NULL,0);
66 sushiv_new_dimension_discrete(s,4,"Iterations",
67 5,(double []){1,10,100,1000,10000},
68 NULL,
69 10,1,
70 0);
72 sushiv_new_dimension_picklist(s,4,"Max Iterations",
74 (double []){100,1000,10000,100000},
75 (char *[]){"one hundred",
76 "one thousand",
77 "ten thousand",
78 "one hundred thousand"},
79 NULL,0);
81 sushiv_new_objective(s,0,"fractal",
82 5,(double []){0, .001, .01, .1, 1.0},
83 fractal_objective,0);
85 sushiv_new_panel_2d(s,0,"Mandel/Julia Fractal",
86 (int []){0,-1},
87 (int []){0,1,2,3,4,-1},
88 0);
90 sushiv_new_panel_1d_linked(s,1,"X Slice",s->objective_list[0]->scale,
91 (int []){0,-1},
92 0,0);
94 sushiv_new_panel_1d_linked(s,2,"Y Slice",s->objective_list[0]->scale,
95 (int []){0,-1},
96 0,SUSHIV_PANEL_LINK_Y | SUSHIV_PANEL_FLIP);
98 return 0;