# BoxOffice2.py
from Processing import *

window(1000, 400)
background(0)

# acquire and parse data
f = open("SocialNetwork10-1-11-7.txt", "r")
lines = f.readlines()
f.close()
print("Read " + str(len(lines)) + " lines.")

# Create list to store earnings
data = []

# Separate earnings and theater count and convert to float
dataMax = 0.0
for l in lines:
    # Convert list of strings to list of floats
    items = l.split(',')
    
    # Save first item for charting
    item = float(items[0])
    data.append( item )
    
    # Find max
    if item > dataMax:
        dataMax = item

# data is now filled, lets do some stuff

# set some graph dimensions
xmin = 50 
ymin = 50
xmax = width()-50 
ymax = height()-50

# Draw graph background
background(175)
noStroke()
fill(251, 255, 229)
rect(xmin, ymin, xmax-xmin, ymax-ymin)
stroke(143, 80, 255)

# Draw points and connect with lines
i = 0
for d in data:
    dx = map(i, 0, len(data)-1, xmin, xmax)
    dy = map(data[i], 0, dataMax, ymax, ymin)
    
    strokeWeight(10)
    point(dx, dy)

    # If not the first point, draw a line
    if i > 0:
        strokeWeight(0.5)
        line(px, py, dx, dy)

    # Save previous point
    px, py = dx, dy
    i += 1
