home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / prog / graphics / hilbert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  1.0 KB  |  88 lines

  1. #include <LEDA/window.h>
  2.  
  3. window W;
  4.  
  5. double x, y, dx, dy;
  6.  
  7. void A(int);
  8. void B(int);
  9. void C(int);
  10. void D(int);
  11.  
  12.  
  13. void plot(double new_x, double new_y)
  14. { W.draw_segment(x,y,new_x,new_y);
  15.   x = new_x;
  16.   y = new_y;
  17.  }
  18.  
  19.  
  20. void A(int i)
  21.   if (i > 0)
  22.   { D(i-1); plot(x-dx,y);
  23.     A(i-1); plot(x,y-dy);
  24.     A(i-1); plot(x+dx,y); 
  25.     B(i-1);
  26.    }
  27.  }
  28.  
  29. void B(int i)
  30.   if (i > 0)
  31.   { C(i-1); plot(x,y+dy);
  32.     B(i-1); plot(x+dx,y);
  33.     B(i-1); plot(x,y-dy); 
  34.     A(i-1);
  35.    }
  36.  }
  37.  
  38.  
  39.  
  40. void C(int i)
  41.   if (i > 0)
  42.   { B(i-1); plot(x+dx,y);
  43.     C(i-1); plot(x,y+dy);
  44.     C(i-1); plot(x-dx,y); 
  45.     D(i-1);
  46.    }
  47.  }
  48.  
  49. void D(int i)
  50.   if (i > 0)
  51.   { A(i-1); plot(x,y-dy);
  52.     D(i-1); plot(x-dx,y);
  53.     D(i-1); plot(x,y+dy); 
  54.     C(i-1);
  55.    }
  56.  }
  57.  
  58.  
  59.  
  60. main()
  61. {   
  62.  int n;
  63.  
  64.  for(;;)
  65.  {
  66.    n = W.read_int("n = ");
  67.  
  68.    double lx = W.xmax() - W.xmin();
  69.    double ly = W.ymax() - W.ymin();
  70.  
  71.    x = W.xmin() + 0.98*lx;
  72.    y = W.ymin() + 0.98*ly;
  73.  
  74.    dx = 0.96 * lx/(1 << n);
  75.    dy = 0.96 * ly/(1 << n);
  76.  
  77.    A(n);
  78.  
  79.    if (W.read_mouse() == 3) break;
  80.  
  81.   }
  82.  
  83. }
  84.