# Makeschematic.py

Jump to: navigation, search
```import sys, pygame, re
from pygame.draw import line

#globals

unitlength = 20

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 col%2 == 0:
xc = xc-10

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 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

size = width, height = 1100, 3000

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

#numrows should be even for now

numrows = 72

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)
arcthelad2= pygame.Rect(0, 0, 2*unitlength, 2*unitlength)

for x in range(numrows/2):
arcthelad.left = 62+(12*4-1)*unitlength
arcthelad.top = 75+4*unitlength*x
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))
arcthelad2.left = 62-unitlength
arcthelad2.top = 75+(4*x+2)*unitlength
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)

num = re.compile('\d+')

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 = (haha[0])%100, (haha[0] * 2)%100, (haha[0] * 3)%100 # darker colors
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))

###

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

#screen = pygame.image.load(blah.bmp)

```