예제 #1
0
def main(in_file, out_file):
    #global im
    #global draw
    global scene
    start_time = parse_file(in_file)
    y = 20
    #im = Image.new("RGB", (WIDTH, HEIGHT), "black")
    #draw = ImageDraw.Draw(im)
    scene = Scene('fplot', HEIGHT, WIDTH)

    for key, values in data.items():
        draw_function(key, values, y)
        y += TRACE_SEPARATOR

    draw_help_lines(y, start_time)

    #f = open(out_file, 'w+')
    #im.save(f, "PNG")
    #f.close
    #print "Width " + str(WIDTH)
    scene.write_svg()
예제 #2
0
from svg import Scene, Rectangle, Circle
from random import randint
import png

filename = "ghostly-teen.png"
r = png.Reader(file=open(filename))
p = list(r.read()[2])
w = len(p[0])
h = len(p)

s = Scene(filename, w, h)
rectangle_count = 0;

class box():
	def __init__(self, x, y, w, h, first=0):
		self.x, self.y, self.w, self.h = x, y, w, h
		#self.filled = first or randint(0,1)
		if first:
			#s.add(Rectangle((x,y),w,h,(255,255,255,0.5)))
			self.filled = 1
			return
		self.filled = sum([sum(g[self.x:self.x+self.w]) for g in p[self.y:self.y+self.h]])
		#print self.filled, 
		if self.filled and not first:
			global rectangle_count 
			rectangle_count += 1
			s.add(Rectangle((x,y),w,h,(255,255,255,1.0)))
		
	def __str__(self):
		return "Box(%d,%d => %d,%d)" % (self.x, self.y, self.x + self.w, self.y + self.h)
	
예제 #3
0
def main():
    kd = kdtree()
    '''kd.insert(6,8)
    kd.insert(3,4)
    kd.insert(5,6)
    kd.insert(4,2)
    kd.insert(8,9)
    kd.insert(9,4)
    kd.insert(9,10)
    kd.printkdtree(kd.root)
    kd.searchtree(4,2)
    print("The minimum in x direction  is ",kd.minimum('x').point[0])
    print("The minimum in y direction is " , kd.minimum('y').point[1])
    print("The maximum in x direction is " , kd.maximum('x'))
    print("The maximum in y direction is " , kd.maximum('y'))
    a=[5,6]
    kd.deletekdnode(a)
    kd.printkdtree(kd.root)
    a=[3,4]
    kd.deletekdnode(a)
    print()
    kd.printkdtree(kd.root)
    print()
    a=[100,50]
    w=kd.deletekdnode(a)
    kd.printkdtree(kd.root)'''
    import random
    ss = []
    scene = Scene('test')
    scene.add(Rectangle((100, 100), 200, 200, (255, 255, 255)))
    for i in range(10):
        m = random.randint(100, 300)
        n = random.randint(100, 300)
        kd.insert(m, n)
        scene.add(Circle((m, n), 3, (0, 255, 0)))
        ss.append(distance([m, n], [100, 150]))
    # kd.printkdtree(kd.root)
    ss.sort()
    print('List:', ss[0])
    p = kd.search_nearest([100, 150])
    # print(p)
    scene.add(Circle((100, 150), 3, (255, 0, 255)))
    x = distance([100, 150], p)
    print('Algo:', x)
    import time
    # time.sleep(1)
    scene.add(Circle((p[0], p[1]), 3, (0, 255, 255)))
    y = 'ETA : ' + str(round(x / 10, 2)) + ' min'
    scene.add(Text((50, 50), y))
    scene.write_svg()
    scene.display()
예제 #4
0
import png
from svg import Scene, Rectangle, Circle

r = png.Reader(file=open("text.png"))
p = list(r.read()[2])

s = Scene("a2d")

for y in range(0,599,10):
	for x in range(0,799,10):
		if sum([sum(g[x:x+10]) for g in p[y:y+10]]):
		#if p[y][x] > 0:
			#s.add(Rectangle((x,y),10,10,(255,255,255,1.0)))
			s.add(Circle((x+5,y+5),5,(255,255,255,1.0)))

s.write_svg()
예제 #5
0
#!/usr/bin/python

import sys
import os
import util
from chemconvert import hash2graph
from html_writer import HtmlWriter
from svg import Scene

html = HtmlWriter("../results/hash_list.html")
util._mkdir("../results/hash_list")

for line in util.parse_text_file(sys.argv[1]):
    print line
    graph = hash2graph(line)
    graph.initialize_pos()
    scene = graph.svg(Scene(200, 200, font_size=12))
    html.write_svg(scene, "../results/hash_list/" + line)

html.display()
예제 #6
0
Gprev = None # a full graph that remembers the last right-hand graph (aligned with the reference graph)
total_reaction_list = [] # a list of 3-tuples that indicate which bonds have changes and by how much

for i in range(0, len(reaction_compounds)):
    print >> sys.stderr, (reaction_titles[i])
    if (reaction_compounds[i] == None):
        html_file.write("<p>" + reaction_titles[i] + "</p>")
        Gref = None
        Gprev = None
        total_reaction_list = []
        continue
         
    (Gl, Gr, Gcommon) = reaction_compounds[i]
    html_file.write("<p>\n")
    html_file.write(reaction_titles[i] + "<br>\n")
    Gl.svg(Scene(500, 200, 14)).embed_in_html(html_file, html_path + "/", pathway + "/step%d_left" % (i))
    Gr.svg(Scene(500, 200, 14)).embed_in_html(html_file, html_path + "/", pathway + "/step%d_right" % (i))
    
    (D, P) = deduce_reaction(Gl, Gr, 10)
    if (D < 0):
        raise Exception("Unable to solve this reaction: " + reaction_titles[i])

    Gl = Gl.permute_nodes(P) # now Gl and Gr are aligned
    
    delta_G = Gr.calculate_total_bond_energy() - Gl.calculate_total_bond_energy()
    activation_energy = Gl.calculate_activation_energy(Gr)

    # expand the graphs and the permutation to include the common compounds too
    Gr.add(Gcommon)
    Gl.add(Gcommon)
    Pexpanded = P + range(len(P), len(P)+Gcommon.get_num_nodes())
예제 #7
0
def main():
    print("Enter the value of k in which you waant to run data Structure")
    k = int(input())
    kd=kdtree(k)
    l=list()
    a=list()
    z=True
    scene = Scene('test')
    scene.add(Rectangle((50,50),300,300,(255,255,255)))
    if k>0:
        for i in range(10):
            for i in range(k):
                rand= random.randint(100,300)
                a.append(rand)

            if k==2:
                scene.add(Circle((a[0],a[1]),3,(0,255,0)))      #Adds circle when k=2
            kd.insert(a)
            #l.append(a)   #if want to do balanced kd trees
            a=[]
         #Testing nearest distance
        '''p=[]
        p=l
        x=[]
        for i in range(len(p)):
            x.append(distance(p[i],[100,100]))
        x.sort()
        print('List :',x[0])'''

        #Code for balanced kd trees
        '''height = 0
        while len(l) > 0:
            axis = height % 2
            if height==0:
                h=1
            else:
                h = height ** 2
            while h > 0 and len(l) != 0:
                l = sorted(l, key=lambda point: point[axis])
                if (len(l) % 2 != 0):
                    n = (len(l) - 1) // 2
                    kd.insert(l[n])
                else:
                    n = (len(l) // 2) - 1
                    kd.insert(l[n])
                l.pop(n)
                h -= -1
            height += 1'''

        print("The kd tree in pre Order Traversal is ")
        kd.printkdtree(kd.root)
        print()
        print()
        o=True
        while o:
            print("-----------------------------------------------------------------------------")
            print("Enter the choice of yours what you wanna do")
            print("1)Search for coordinates in KD tree")
            print("2)Find minimum in given dimension")
            print("3)Find maximum in given dimension")
            print("4)To delete node in KD tree")
            if k==2:
                print("5)To search the nearest neighbour of entered point")
            g=int(input())

            print("******************************************************************************")
            if g==1:
                print("Enter the coordinates you want to check in the tree are present or not")
                a=list((map(int,input().split(" "))))
                kd.searchtree(a)
                a=[]
            if g==2:
                print("Enter the Dimension number[0,k)? ")
                a = int(input())
                if a>=0 and a<k:
                    t=kd.minimum(a).point[a]
                    a = []
                    print("The minimum is :",end="  ")
                    print(t)
                else:
                    print("Please enter the correct dimension")

            if g==3:
                print("Enter the dimension number [0-k)? ")
                a = int(input())
                if a>=0 and a<k:
                    t = kd.maximum(a)
                    a = []
                    print("The maximum is :",end="  ")
                    print(t)
                else:
                    print("Enter the correct dimension")
            if g==4:
                print("Enter the coordinates of the node you want to delete")
                a = list(map(int,input().split()))
                t = kd.deletekdnode(a)
                a = []
                print("Tree after deletion is :")
                kd.printkdtree(kd.root)
                print()
        #Nearest Neighbour search in Two dimension
            if k==2 and g==5:
                print("Enter the point where you want to do the nearest search")
                p=[]
                p=list(map(int,input().split()))
                b=kd.search_nearest(p)
                print("The nearest Neighbour is present at the location ",b)
                x=distance(p,b)
                print("The distance of the nearest neighbour is ",x)
                scene.add(Circle((p[0],p[1]),3,(255,0,0)))
                scene.add(Circle((b[0],b[1]),3,(0,0,0)))
                # y='ETA : '+str(round(x/10,2))+' min' #ETA value ( Hypothetical)
                # scene.add(Text((100,20),y))
                scene.write_svg()
                scene.display()
                scene.add(Circle((b[0],b[1]),3,(0,255,0)))
                scene.add(Circle((p[0],p[1]),3,(255,255,255)))

            print("*****************************************************************")
            print("Continue operating on created Tree enter 1 else any other integer")
            ans=int(input())
            if ans!=1:
                o=False
    else:
        print("Enter correct value of k")