Pythagorean tree
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"]
]