# GridTweets2.py
# Values drawn in a color grid

# Adapted from Jer Thorp
# http:#blog.blprnt.com/blog/blprnt/your-random-numbers-getting-started-with-processing-and-data-visualization

# The Hitchhiker's Guide to the Galaxy
# Douglas Adams
#
# In the first novel and radio series, a group of hyper-intelligent
# pan-dimensional beings demand to learn the Ultimate Answer to the
# Ultimate Question of Life, The Universe, and Everything from the
# supercomputer, Deep Thought, specially built for this purpose.
# It takes Deep Thought 7 million years to compute and check the
# answer, which turns out to be 42. Unfortunately, the problem is
# The Ultimate Question itself is unknown. 

from Processing import *
window(600,600)
background(0)
stroke(32)
strokeWeight(0.5)

def colorGrid(nums, x, y, s):
    # Make a list of number counts filled with 0's
    counts = [0 for i in range(100)]

    # Tally the counts
    for i in range(len(nums)):
    	counts[ nums[i] ] += 1

    # Move the drawing coordinates to the x,y position specified in the parameters
    pushMatrix()
    translate(x,y)

    # Draw the grid
    for i in range( len(counts) ):
        fill(counts[i] * 30, 0, 0, counts[i] * 20)
        textAlign(CENTER, CENTER)
        textSize(s/2)
        text(i, (i % 10) * s, floor(i/10) * s, s, s)
        noFill()
        rect((i % 10) * s, floor(i/10) * s, s, s)
 
    popMatrix()

# Load strings and convert to integers
f = open("numbers.txt", "r")
snumbers = f.readlines()
f.close()
numbers = [ int(s) for s in snumbers ]

# Draw the color grid
colorGrid(numbers, 50, 50, 50)
