fractree.box

Pythagorean tree

../../_images/fractree.png

You can already do some moderately complex programming with Box. However the capabilities of the language are going to improve substantially in the near future. To run this example you will need the following file(s): ./fractree.box. If the example requires more than one file, then you should put them into the same directory. You can then launch Box with box -l g ./fractree.box.

include "g"

// We define a new object, which contains all the details about
// the Pythagorean tree
PythagTree = (Int level, Point p1, p2, Real xmid, h)

PythagTree@Window[
  xmid = $.xmid, h = $.h, level = $.level, p1 = $.p1, p2 = $.p2, d = 1e-10
  Color[g = 1.0/(level+1), b = 1 - g, (0.5*b, g, 0)]

  side = Points[p1, p2]
  p = Poly[side.Get[0], side.Get[1-d], side.Get[(1-d, 1)], side.Get[(0, 1)]]
  t = Points[p.Get[2], p.Get[3], p.Get[(2+xmid, -h)]]

  p // Pass the Polygon to the window for drawing

  If[level >= 1]
    PythagTree[.level = level-1, .xmid = xmid, .h = h
               .p1 = t.Get[2], .p2 = t.Get[0]]
    PythagTree[.level = level-1, .xmid = xmid, .h = h
               .p1 = t.Get[1], .p2 = t.Get[2]]
]

w = Window[][
  BBox[(-34, 89), (80, 2)]

  // Now we can drwa the tree with the line above
  PythagTree[.level=11, .xmid=0.6, .h=0.45, .p1=(5, 10), .p2=(25, 10)]
  .Save["fractree.png"]
]

Table Of Contents



This Page



Get The figure description language: Box at SourceForge.net. Fast, secure and Free Open Source software downloads