PageRenderTime 19ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/ocaml/shapes/example.c

#
C | 50 lines | 40 code | 9 blank | 1 comment | 11 complexity | 73f43eb85c2b16c9fc0b9f9401008a8a MD5 | raw file
 1/* File : example.c */
 2#include <stdio.h>
 3#include "example.h"
 4
 5shape::~shape() { }
 6
 7bool shape::cover( double x, double y ) { return false; }
 8
 9void 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
20void 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
48double volume::depth( double x, double y ) { return 0.0; }
49
50volume::~volume() { }