# V11.py

```
import sys, pygame, re
from pygame.draw import line

#globals

unitlength = 40

def getcolend(acol, arrow):
if arrow%2 == 0:
return 62 + acol*4*unitlength+unitlength/2
else:
return 62 + acol*4*unitlength+unitlength*7/2

def getrowloc(arow):
if arow%2 == 0:
return 75+2*unitlength*arow+unitlength/2
else:
return 75+2*unitlength*arow-unitlength/2

def drawat(x,y,z, screener, cola1): #draw from (x,y) to (x,z)

yc = getrowloc(x)

if y < z:
xca = 62+4*unitlength*y+unitlength/2
xcb = 62+4*unitlength*z+7*unitlength/2
line(screener, cola1, (xca, yc), (xcb, yc),1)
else:
xca = 62+4*unitlength*z+unitlength/2
xcb = 62+4*unitlength*y+7*unitlength/2

line(screener, cola1, (xca, yc), (xcb, yc),1)

def drawup(col, row1, row2, screener, oliga, cola2,fonz): #draw from (y,x) to (z,x)

yc1 = getrowloc(row1)
yc2 = getrowloc(row2)

xc = getcolend(col, row1)

#line(screener, cola2, (xc, yc1), (xc, yc2),1)

if yc2 > yc1:   #swap so that yc1 > yc2
temp = yc1
yc1 = yc2
yc2 = temp

arcalad = pygame.Rect(xc-(yc1-yc2)/50-3, yc2, 2*((yc1-yc2)/50+3), yc1-yc2)

if col%2 == 0:
pygame.draw.arc(screener, cola2, arcalad, 1.57, 4.71, 1)
xc = xc-10
else:
pygame.draw.arc(screener, cola2, arcalad, -1.57, 1.57, 1)

screener.blit(fonz.render(str(oliga),1,cola2),(xc,yc1))
screener.blit(fonz.render(str(oliga),1,cola2),(xc,yc2))

drawat(row1, col, col, screener, cola2)    #possibly draws over previously drawn segments
drawat(row2, col, col, screener, cola2)

def modpow(thing, power, mod):
ret = 1
for x in range(power):
ret = (thing*ret)%mod
return ret

def maked(inf, outf):

pygame.init()

font18=pygame.font.Font("arial.TTF",18)
font12=pygame.font.Font("arial.TTF",12)

black = 0, 0, 0
white = 250, 250, 250
numrows = 0
numcols = 12
num = re.compile('\d+')

for lin in open(inf, 'r'):
haha = num.findall(lin)
haha[0] = int(haha[0])
haha[1] = int(haha[1])
haha[2] = int(haha[2])
if haha[1] > numrows:
numrows = haha[1]

numrows = numrows+1
size = width, height = 2*62+4*unitlength*numcols,74+2*unitlength*numrows

screen = pygame.display.set_mode(size)
screen.fill(white)

#numrows should be even for now

oligo = -1

row = 0
col = 0
xc = 0
yc = 0

oligocolor = 0,0,0

for lin in open(inf, 'r'):
haha = num.findall(lin)
haha[0] = int(haha[0])
haha[1] = int(haha[1])
haha[2] = int(haha[2])
oligocolor = modpow(3,haha[0],201), modpow(37,numrows-haha[0],225), modpow(13,haha[0],250)
if haha[1] > numrows:
numrows = haha[1]
if haha[0] != oligo:    #arrows
if (oligo != -1):
yc = getrowloc(row)
xc = getcolend(col, row)
if row%2 == 0:
pygame.draw.polygon(screen, oligocolor, ((xc,yc+unitlength/5),(xc,yc-unitlength/5),(xc-unitlength/2,yc)), 0)
screen.blit(font18.render(str(oligo),1,oligocolor),(xc,yc))
elif row%2 == 1:
pygame.draw.polygon(screen, oligocolor, ((xc,yc+unitlength/5),(xc,yc-unitlength/5),(xc+unitlength/2,yc)), 0)
screen.blit(font18.render(str(oligo),1,oligocolor),(xc,yc))
oligo = haha[0]
row = haha[1]
col = haha[2]
pygame.draw.circle(screen, oligocolor, (getcolend(col, row+1), getrowloc(row)), 2, 0)
else:
if haha[1] == row:
drawat(row, col, haha[2], screen, oligocolor)
else:
drawup(col, row, haha[1], screen, oligo, oligocolor, font12)
row = haha[1]
col = haha[2]

#didn't take care of last oligo in above
yc = getrowloc(row)
xc = getcolend(col, row)
if row%2 == 0:
pygame.draw.polygon(screen, oligocolor, ((xc,yc+unitlength/5),(xc,yc-unitlength/5),(xc-unitlength/2,yc)), 0)
screen.blit(font18.render(str(oligo),1,oligocolor),(xc,yc))
elif row%2 == 1:
pygame.draw.polygon(screen, oligocolor, ((xc,yc+unitlength/5),(xc,yc-unitlength/5),(xc+unitlength/2,yc)), 0)
screen.blit(font18.render(str(oligo),1,oligocolor),(xc,yc))

for x in range(11):
line(screen, (175,175,175), (62+4*unitlength*(x+1), 0), (62+4*unitlength*(x+1), 3000), 1)

for x in range(12):
screen.blit(font18.render(str(x),1,black),(62+unitlength*(4*x+2)-5,32))

#rects for making arcs
arcthelad = pygame.Rect(0, 0, 2*unitlength, 2*unitlength)

for x in range(numrows/2):
screen.blit(font18.render(str(2*x),1,black),(31,75+unitlength*4*x-9))
line(screen, (0,0,0), (62, 75+unitlength*4*x), (62+12*4*unitlength, 75+4*unitlength*x),1)
pygame.draw.arc(screen, (250,0,0), arcthelad, -1.57, 1.57, 1)
screen.blit(font18.render(str(2*x+1),1,black),(31,75+(4*x+2)*unitlength-9))
line(screen, (0,0,0), (62+12*4*unitlength, 75+(4*x+2)*unitlength), (62, 75+(4*x+2)*unitlength),1)
pygame.draw.arc(screen, (250,0,0), arcthelad2, 1.57, 4.71, 1)

###

pygame.image.save(screen, outf)
pygame.quit()