home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / examples / trwthlfs.lsy < prev    next >
Text File  |  1992-10-30  |  2KB  |  87 lines

  1. /*
  2.  * Tree model from the book 'The algorithmic beauty of plants'
  3.  * by P. Prudinkiewicz and A. Lindenmayer, p. 60.
  4.  *
  5.  * Leafs are added to the model described in the book. This is
  6.  * realized using macros. The leaf model is out of the book as well.
  7.  * (p. 124).
  8.  *
  9.  *  30.10.92  Christoph Streit (streit@iam.unibe.ch)
  10.  */
  11.  
  12. lsystem TreeWithLeafs;
  13.  
  14. /*
  15.  * Generate trunk and branches.
  16.  */
  17. table Tree {
  18.   const d1 = 180.0;  // divergence angle 1
  19.         d2 = 252;    // divergence angle 2
  20.         a  = 36;     // branching angle
  21.         lr = 1.070;  // elongation rate
  22.         vr = 1.732;  // width increase rate
  23.         vr2 = 1;     // width increase rate 2
  24.  
  25.    A(n):n < 4 ->  we(0.001) wi(vr) F(50) 
  26.                    [pt(a) F(50) A(n+1)] ro(-d1)
  27.                    [pt(a) F(50) A(n+1)] ro(-d2)
  28.                    [pt(a) F(50) A(n+1)];
  29.  
  30.    A(n):n >= 4 -> we(1) wi(vr2) F(50) 
  31.                    [pt(a) F(50) leafs A(n+1)] ro(-d1)
  32.                    [pt(a) F(50) leafs A(n+1)] ro(-d2)
  33.                    [pt(a) F(50) leafs A(n+1)];
  34.    F(l)  -> F(l*lr);
  35.    wi(w) -> wi(w*vr); 
  36. };
  37.  
  38. /*
  39.  * Attach the leafs to the branches.
  40.  */
  41. table Leafs {
  42.   leafs -> [
  43.             [pt(45) F(15,0.4) [pt(45)  xm("leaf", 0.1)]
  44.                               [pt(-45) xm("leaf", 0.1)]
  45.                               xm("leaf", 0.1)
  46.             ]
  47.             [pt(-45) F(15,0.4) [pt(45)  xm("leaf", 0.1)]
  48.                                [pt(-45) xm("leaf", 0.1)]
  49.                                xm("leaf", 0.1)
  50.             ]
  51.            ];
  52. };
  53.  
  54. /*
  55.  * Macro definition for the leaf, which will be attached due to 
  56.  * the table Leafs.
  57.  */    
  58. table LeafDef {
  59.   const    LA=5;     // initial length - main segment
  60.         RA=1.1;   // growth rate - main segment
  61.         LB=2.2;   // initial length - lateral segment
  62.         RB=1.21;  // growth rate - lateral segment
  63.         SD=1;     
  64.         DW=1.01;  
  65.         PD=0.9;   // growth potential decrement
  66.  
  67.    leafDef -> sm("leaf") 
  68.            { co("green") sv C(0) } 
  69.           em;
  70.  
  71.    C(t) -> f(LA, 1, RA)
  72.        [
  73.              tu(-60) B(t) sv][C(t+1)][tu(60) B(t) sv
  74.        ];
  75.    B(t) : t>0 -> f(LB, SD, RB) B(t-PD);
  76.    f(s,w,r) -> f(s*r, w*DW, r);
  77. };
  78.  
  79. attributes {
  80.    axiom  t(1,0,0, 0) // add some tropism
  81.           leafDef     // generate the leaf macro
  82.           co("SaddleBrown") wi(1) F(200) ro(-45) A(1);
  83.    derivation Tree(6), Leafs(1), LeafDef(20);
  84.  
  85.    coneres 5;
  86. };
  87.