import source from 1.3.40
[external/swig.git] / Examples / ocaml / shapes / example.c
1 /* File : example.c */
2 #include <stdio.h>
3 #include "example.h"
4
5 shape::~shape() { }
6
7 bool shape::cover( double x, double y ) { return false; }
8
9 void draw_shape_coverage( shape *s, int div_x, int div_y ) {
10     double i,j;
11
12     for( i = 0; i < 1.0; i += 1.0 / ((float)div_y) ) {
13         for( j = 0; j < 1.0; j += 1.0 / ((float)div_x) ) {
14             if( s->cover( j,i ) ) putchar( 'x' ); else putchar( ' ' );
15         }
16         printf( "\n" );
17     }
18 }
19
20 void draw_depth_map( volume *v, int div_x, int div_y ) {
21     double i,j;
22     char depth_map_chars[] = "#*+o;:,. ";
23     double lowbound, highbound;
24     double current = 0.0;
25     bool bounds_set = false;
26
27     for( i = 0; i < 1.0; i += 1.0 / ((float)div_y) ) {
28         for( j = 0; j < 1.0; j += 1.0 / ((float)div_x) ) {
29             current = v->depth( j,i );
30             if( !bounds_set ) { 
31                 lowbound = current; highbound = current; bounds_set = true;
32             }
33             if( current < lowbound ) lowbound = current;
34             if( current > highbound ) highbound = current;
35         }
36     }
37
38     for( i = 0; i < 1.0; i += 1.0 / ((float)div_y) ) {
39         for( j = 0; j < 1.0; j += 1.0 / ((float)div_x) ) {
40             current = ((v->depth( j,i ) - lowbound) / 
41                        (highbound - lowbound)) * 8;
42             putchar(depth_map_chars[(int)current]);
43         }
44         putchar('\n');
45     }
46 }
47
48 double volume::depth( double x, double y ) { return 0.0; }