PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C | 50 lines | 40 code | 9 blank | 1 comment | 11 complexity | 73f43eb85c2b16c9fc0b9f9401008a8a MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* File : example.c */
  2. #include <stdio.h>
  3. #include "example.h"
  4. shape::~shape() { }
  5. bool shape::cover( double x, double y ) { return false; }
  6. void draw_shape_coverage( shape *s, int div_x, int div_y ) {
  7. double i,j;
  8. for( i = 0; i < 1.0; i += 1.0 / ((float)div_y) ) {
  9. for( j = 0; j < 1.0; j += 1.0 / ((float)div_x) ) {
  10. if( s->cover( j,i ) ) putchar( 'x' ); else putchar( ' ' );
  11. }
  12. printf( "\n" );
  13. }
  14. }
  15. void draw_depth_map( volume *v, int div_x, int div_y ) {
  16. double i,j;
  17. char depth_map_chars[] = "#*+o;:,. ";
  18. double lowbound, highbound;
  19. double current = 0.0;
  20. bool bounds_set = false;
  21. for( i = 0; i < 1.0; i += 1.0 / ((float)div_y) ) {
  22. for( j = 0; j < 1.0; j += 1.0 / ((float)div_x) ) {
  23. current = v->depth( j,i );
  24. if( !bounds_set ) {
  25. lowbound = current; highbound = current; bounds_set = true;
  26. }
  27. if( current < lowbound ) lowbound = current;
  28. if( current > highbound ) highbound = current;
  29. }
  30. }
  31. for( i = 0; i < 1.0; i += 1.0 / ((float)div_y) ) {
  32. for( j = 0; j < 1.0; j += 1.0 / ((float)div_x) ) {
  33. current = ((v->depth( j,i ) - lowbound) /
  34. (highbound - lowbound)) * 8;
  35. putchar(depth_map_chars[(int)current]);
  36. }
  37. putchar('\n');
  38. }
  39. }
  40. double volume::depth( double x, double y ) { return 0.0; }
  41. volume::~volume() { }