<s> from gen import Tree <EOL> from math import atan , cos , sin , pi <EOL> import demo_trees ; reload ( demo_trees ) <EOL> from demo_trees import trees <EOL> from buchheim import buchheim as layout <EOL> tree = trees [ <NUM_LIT:4> ] [ <NUM_LIT:1> ] <EOL> tree [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] . children . append ( Tree ( "<STR_LIT:a>" ) ) <EOL> tree [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] . children . append ( Tree ( "<STR_LIT:b>" ) ) <EOL> t = layout ( trees [ <NUM_LIT:4> ] [ <NUM_LIT:1> ] ) <EOL> r = <NUM_LIT:30> <EOL> rh = r * <NUM_LIT> <EOL> rw = r * <NUM_LIT:2> <EOL> stroke ( <NUM_LIT:0> ) <EOL> def drawt ( root , depth ) : <EOL> global r <EOL> oval ( root . x * rw , depth * rh , r , r ) <EOL> for child in root . children : <EOL> drawt ( child , depth + <NUM_LIT:1> ) <EOL> def drawconn ( root , depth ) : <EOL> for child in root . children : <EOL> line ( root . x * rw + ( r / <NUM_LIT:2> ) , depth * rh + ( r / <NUM_LIT:2> ) , <EOL> child . x * rw + ( r / <NUM_LIT:2> ) , ( depth + <NUM_LIT:1> ) * rh + ( r / <NUM_LIT:2> ) ) <EOL> drawconn ( child , depth + <NUM_LIT:1> ) <EOL> def dottedline ( x1 , y1 , x2 , y2 ) : <EOL> segment = <NUM_LIT:5> <EOL> if x2 - x1 > <NUM_LIT:0> : <EOL> theta = atan ( float ( y2 - y1 ) / float ( x2 - x1 ) ) <EOL> else : <EOL> theta = pi + atan ( float ( y2 - y1 ) / float ( x2 - x1 ) ) <EOL> dx = cos ( theta ) * segment <EOL> dy = sin ( theta ) * segment <EOL> xdir = x1 < x2 <EOL> ydir = y1 < y2 <EOL> while <NUM_LIT:1> : <EOL> if xdir != ( x1 < x2 ) or ydir != ( y1 < y2 ) : break <EOL> line ( x1 , y1 , x1 + dx , y1 + dy ) <EOL> x1 , y1 = x1 + <NUM_LIT:2> * dx , y1 + <NUM_LIT:2> * dy <EOL> def drawthreads ( root , depth ) : <EOL> for child in root . children : <EOL> c = child . thread <EOL> if c : <EOL> dottedline ( child . x * rw + ( r / <NUM_LIT:2> ) , ( depth + <NUM_LIT:1> ) * rh + ( r / <NUM_LIT:2> ) , <EOL> c . x * rw + ( r / <NUM_LIT:2> ) , ( depth + <NUM_LIT:2> ) * rh + ( r / <NUM_LIT:2> ) ) <EOL> drawthreads ( child , depth + <NUM_LIT:1> ) <EOL> size ( <NUM_LIT:1000> , <NUM_LIT> ) <EOL> translate ( <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> stroke ( <NUM_LIT:0> ) <EOL> drawconn ( t , <NUM_LIT:0> ) <EOL> drawthreads ( t , <NUM_LIT:0> ) <EOL> fill ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> drawt ( t , <NUM_LIT:0> ) </s>
