#!/usr/bin/env python # encoding: utf-8 """ graph.py Created by Cody on 2009-11-12. Copyright (c) 2009 __MyCompanyName__. All rights reserved. """ import sys import os import random import math from names import * from Tkinter import * root = Tk() canvas = Canvas(width=1000, height=600, bg='black') canvas.pack(expand=YES, fill=BOTH) tmpNames = [0 for i in range(len(nameList))] tmpCount = 0 def connectionRule(name1, name2): sum1val = 0 sum2val = 0 if(name1 == name2): return False for i in range(0, len(name1)): sum1val += ord(name1[i]) for i in range(0, len(name2)): sum2val += ord(name2[i]) if(sum1val == sum2val): return True return False def drawcircle(canv,x,y,radius,color): canv.create_oval(x-radius,y-radius,x+radius,y+radius,width=0,fill=color) def main(): tmpCount = 0 for name1 in nameList: for name2 in nameList: if(connectionRule(name1, name2)): tmpCount += 1 tmpNames[tmpCount] = name2 rootx = random.randint(0,1000) rooty = random.randint(0,600) if tmpCount != 0: spacing = 360/tmpCount currSpace = 0 radius = 15 * (tmpCount/10.0) # Relate radius to number of nodes #nodes connected with root for i in range(0, tmpCount): x = rootx + radius * math.cos( (currSpace * math.pi) / 180) y = rooty + radius * math.sin( (currSpace * math.pi) / 180) drawcircle(canvas, x, y, 3, 'blue') canvas.create_line(x,y, rootx, rooty, fill = 'white', width=1) currSpace += spacing # Root node drawcircle(canvas, rootx, rooty, 5, 'red') tmpCount = 0 root.mainloop() if __name__ == '__main__': main()