Permalink
Browse files

Updating to article version

  • Loading branch information...
1 parent dfde211 commit 50e296d6fa2bc822b36c8abaec48d5cefbe6a188 Bill Mill committed May 2, 2008
Showing with 411 additions and 56 deletions.
  1. +34 −0 demo_trees.py
  2. +21 −4 draw_nary.py
  3. +29 −0 figure1.py
  4. +29 −0 figure2.py
  5. +29 −0 figure3.py
  6. +30 −0 figure4.py
  7. +35 −0 figure5.py
  8. +60 −0 figure6.py
  9. +67 −0 figure7.py
  10. +71 −42 reingold_addmod.py
  11. +4 −4 test_tree.py
  12. +2 −6 ws2.py
View
@@ -140,4 +140,38 @@
Tree("M2"),
Tree("M3"))),
Tree("D3")),
+
+#10 big tree for testing
+Tree("t",
+ Tree("rr",
+ Tree("rr1",
+ Tree("yy",
+ Tree("ab"), Tree("bc")),
+ Tree("zz",
+ Tree("a"),
+ Tree("b",
+ Tree("c"),
+ Tree("d",
+ Tree("e"),
+ Tree("f",
+ Tree("g"),
+ Tree("h",
+ Tree("i"))))))),
+ Tree("rr2", Tree("rr22"))),
+ Tree("root",
+ Tree("l1",
+ Tree("ll1"),
+ Tree("lr1",
+ Tree("lrl"),
+ Tree("lrr"))),
+ Tree("r1",
+ Tree("rr2",
+ Tree("rr3",
+ Tree("rrl",
+ Tree("rrll",
+ Tree("rrlll",
+ Tree("98"), Tree("99")),
+ Tree("rrllr")),
+ Tree("rrlr"))))))),
+
]
View
@@ -1,12 +1,21 @@
from gen import Tree
+import demo_trees; reload(demo_trees)
from demo_trees import trees
import reingold_thread; reload(reingold_thread)
from reingold_thread import reingold_tilford as rt
#from reingold_naive import reingold_tilford as rt
import buchheim; reload(buchheim)
from buchheim import buchheim
-t = buchheim(trees[6])
+def mirror(t):
+ if len(t.children) > 1:
+ t.children = tuple(reversed(t.children))
+ for c in t.children:
+ mirror(c)
+ return t
+
+t = buchheim(trees[8])
+#t = buchheim(trees[9])
#t = rt(trees[4])
r = 30
@@ -17,6 +26,13 @@
def drawt(root, depth):
global r
oval(root.x * rw, depth * rh, r, r)
+ fill(0)
+ fontsize(10)
+ try:
+ text(" %s\n%s,%s" % (root.tree, round(root.x, 2), round(root.mod)),
+ root.x * rw + 4, depth * rh + rh/5)
+ except: pass
+ fill(1)
for child in root.children:
drawt(child, depth+1)
@@ -34,8 +50,9 @@ def sign(x):
from math import atan, sin, cos, pi
def dottedline(x1, y1, x2, y2):
segment = 5
- if x2 == x1: print "fucked up"; return
- if x2 - x1 > 0:
+ if x2 == x1:
+ theta = pi/2
+ elif x2 - x1 > 0:
theta = atan(float(y2-y1)/float(x2-x1))
else:
theta = pi + atan(float(y2-y1)/float(x2-x1))
@@ -58,7 +75,7 @@ def drawthreads(root, depth):
c.x * rw + (r/2), (depth+2) * rh + (r/2))
drawthreads(child, depth+1)
-size(500, 500)
+size(1000, 550)
translate(2, 2)
drawconn(t, 0)
stroke(0,.4,.6)
View
@@ -0,0 +1,29 @@
+from gen import Tree
+from demo_trees import trees
+from buchheim import buchheim
+
+t = buchheim(trees[6])
+
+r = 30
+rh = r*1.5
+rw = r*1.5
+stroke(0)
+
+def drawt(root, depth):
+ global r
+ oval(root.x * rw, depth * rh, r, r)
+ for child in root.children:
+ drawt(child, depth+1)
+
+def drawconn(root, depth):
+ for child in root.children:
+ line(root.x * rw + (r/2), depth * rh + (r/2),
+ child.x * rw + (r/2), (depth+1) * rh + (r/2))
+ drawconn(child, depth+1)
+
+size(1000, 500)
+translate(2, 2)
+stroke(0)
+drawconn(t, 0)
+fill(1,1,1)
+drawt(t, 0)
View
@@ -0,0 +1,29 @@
+from gen import Tree
+from demo_trees import trees
+from knuth import layout
+
+t = layout(trees[2])
+
+r = 30
+rh = r*1.5
+rw = r*1.5
+stroke(0)
+
+def drawt(root, depth):
+ global r
+ oval(root.x * rw, depth * rh, r, r)
+ for child in root.children:
+ drawt(child, depth+1)
+
+def drawconn(root, depth):
+ for child in root.children:
+ line(root.x * rw + (r/2), depth * rh + (r/2),
+ child.x * rw + (r/2), (depth+1) * rh + (r/2))
+ drawconn(child, depth+1)
+
+size(1000, 500)
+translate(2, 2)
+stroke(0)
+drawconn(t, 0)
+fill(1,1,1)
+drawt(t, 0)
View
@@ -0,0 +1,29 @@
+from gen import Tree
+from demo_trees import trees
+from ws1 import layout
+
+t = layout(trees[4])
+
+r = 30
+rh = r*1.5
+rw = r*1.5
+stroke(0)
+
+def drawt(root, depth):
+ global r
+ oval(root.x * rw, depth * rh, r, r)
+ for child in root.children:
+ drawt(child, depth+1)
+
+def drawconn(root, depth):
+ for child in root.children:
+ line(root.x * rw + (r/2), depth * rh + (r/2),
+ child.x * rw + (r/2), (depth+1) * rh + (r/2))
+ drawconn(child, depth+1)
+
+size(1000, 500)
+translate(2, 2)
+stroke(0)
+drawconn(t, 0)
+fill(1,1,1)
+drawt(t, 0)
View
@@ -0,0 +1,30 @@
+from gen import Tree
+from demo_trees import trees
+import ws2; reload(ws2)
+from ws2 import layout
+
+t = layout(trees[3])
+
+r = 30
+rh = r*1.5
+rw = r*1.5
+stroke(0)
+
+def drawt(root, depth):
+ global r
+ oval(root.x * rw, depth * rh, r, r)
+ for child in root.children:
+ drawt(child, depth+1)
+
+def drawconn(root, depth):
+ for child in root.children:
+ line(root.x * rw + (r/2), depth * rh + (r/2),
+ child.x * rw + (r/2), (depth+1) * rh + (r/2))
+ drawconn(child, depth+1)
+
+size(1000, 500)
+translate(2, 2)
+stroke(0)
+drawconn(t, 0)
+fill(1,1,1)
+drawt(t, 0)
View
@@ -0,0 +1,35 @@
+from gen import Tree
+from demo_trees import trees
+from buchheim import buchheim as layout
+
+t = layout(trees[3][1])
+t2 = layout(trees[3][0])
+
+r = 30
+rh = r*1.5
+rw = r*1.5
+stroke(0)
+
+def drawt(root, depth, offset=0):
+ global r
+ oval((root.x * rw) + offset, depth * rh, r, r)
+ fill(0)
+ text(str(int(round(root.x*2, 0))), (root.x * rw) + rw/6 + offset, (depth * rh) + rh/2)
+ fill(1)
+ for child in root.children:
+ drawt(child, depth+1, offset)
+
+def drawconn(root, depth, offset=0):
+ for child in root.children:
+ line(root.x * rw + (r/2) + offset, depth * rh + (r/2),
+ child.x * rw + (r/2) + offset, (depth+1) * rh + (r/2))
+ drawconn(child, depth+1, offset)
+
+size(1000, 500)
+translate(2, 2)
+stroke(0)
+drawconn(t2, 0)
+drawconn(t, 0, 80)
+fill(1,1,1)
+drawt(t2, 0)
+drawt(t, 0, 80)
View
@@ -0,0 +1,60 @@
+from gen import Tree
+from math import atan, cos, sin, pi
+import demo_trees; reload(demo_trees)
+from demo_trees import trees
+from buchheim import buchheim as layout
+
+tree = trees[4][1]
+tree[0][1].children.append(Tree("a"))
+tree[0][1].children.append(Tree("b"))
+t = layout(trees[4][1])
+
+r = 30
+rh = r*1.5
+rw = r*2
+stroke(0)
+
+def drawt(root, depth):
+ global r
+ oval(root.x * rw, depth * rh, r, r)
+ for child in root.children:
+ drawt(child, depth+1)
+
+def drawconn(root, depth):
+ for child in root.children:
+ line(root.x * rw + (r/2), depth * rh + (r/2),
+ child.x * rw + (r/2), (depth+1) * rh + (r/2))
+ drawconn(child, depth+1)
+
+def dottedline(x1, y1, x2, y2):
+ segment = 5
+ if x2 - x1 > 0:
+ theta = atan(float(y2-y1)/float(x2-x1))
+ else:
+ theta = pi + atan(float(y2-y1)/float(x2-x1))
+
+ dx = cos(theta) * segment
+ dy = sin(theta) * segment
+ xdir = x1 < x2
+ ydir = y1 < y2
+
+ while 1:
+ if xdir != (x1 < x2) or ydir != (y1 < y2): break
+ line(x1, y1, x1+dx, y1+dy)
+ x1, y1 = x1+2*dx, y1+2*dy
+
+def drawthreads(root, depth):
+ for child in root.children:
+ c = child.thread
+ if c:
+ dottedline(child.x * rw + (r/2), (depth+1) * rh + (r/2),
+ c.x * rw + (r/2), (depth+2) * rh + (r/2))
+ drawthreads(child, depth+1)
+
+size(1000, 500)
+translate(2, 2)
+stroke(0)
+drawconn(t, 0)
+drawthreads(t, 0)
+fill(1,1,1)
+drawt(t, 0)
View
@@ -0,0 +1,67 @@
+from gen import Tree
+from math import atan, cos, sin, pi
+import demo_trees; reload(demo_trees)
+from demo_trees import trees
+import buchheim; reload(buchheim)
+from buchheim import buchheim as layout
+
+t = layout(trees[8])
+
+r = 30
+rh = r*1.5
+rw = r*1.5
+stroke(0)
+
+def jimmy(root):
+ if root.tree.__str__() == "m1": root.x -= .83
+ if root.tree.__str__() == "m2": root.x -= 1.67
+ if root.tree.__str__() in ("m3", "m31"): root.x -= 1.5
+ for child in root.children:
+ jimmy(child)
+
+def drawt(root, depth):
+ oval(root.x * rw, depth * rh, r, r)
+ for child in root.children:
+ drawt(child, depth+1)
+
+def drawconn(root, depth):
+ for child in root.children:
+ line(root.x * rw + (r/2), depth * rh + (r/2),
+ child.x * rw + (r/2), (depth+1) * rh + (r/2))
+ drawconn(child, depth+1)
+
+def dottedline(x1, y1, x2, y2):
+ segment = 5
+ if x2 == x1:
+ theta = pi/2
+ elif x2 - x1 > 0:
+ theta = atan(float(y2-y1)/float(x2-x1))
+ else:
+ theta = pi + atan(float(y2-y1)/float(x2-x1))
+
+ dx = cos(theta) * segment
+ dy = sin(theta) * segment
+ xdir = x1 < x2
+ ydir = y1 < y2
+
+ while 1:
+ if xdir != (x1 < x2) or ydir != (y1 < y2): break
+ line(x1, y1, x1+dx, y1+dy)
+ x1, y1 = x1+2*dx, y1+2*dy
+
+def drawthreads(root, depth):
+ for child in root.children:
+ c = child.thread
+ if c:
+ dottedline(child.x * rw + (r/2), (depth+1) * rh + (r/2),
+ c.x * rw + (r/2), (depth+2) * rh + (r/2))
+ drawthreads(child, depth+1)
+
+size(1000, 500)
+translate(2, 2)
+stroke(0)
+jimmy(t)
+drawconn(t, 0)
+drawthreads(t, 0)
+fill(1,1,1)
+drawt(t, 0)
Oops, something went wrong.

0 comments on commit 50e296d

Please sign in to comment.