from drawtool import DrawTool import random import text_analyzer as text dt = DrawTool() dt.set_XY_range(0,15, 0,12) dt.set_aspect('equal') dt.set_axes_off() # Change this to see a different layout: random.seed(1234) #filename = 'darwin.txt' filename = 'federalist_papers.txt' # Compute the noun count text.compute_noun_count(filename) # Top n words: n = 10 # Largest size: max_font = 30 (noun, count) = text.get_top() max_count = count for i in range(n): print(noun, 'occurs', count, 'times') # Font size based on proportion to most frequently occuring noun. font_size = int( (count / max_count) * max_font ) # A random place to draw: x = random.uniform(0,10) y = random.uniform(0,10) dt.draw_text(x, y, noun, font_size) # Remove this noun from the dictionary text.noun_count.pop(noun) # Get the next pair (noun, count) = text.get_top() dt.display()