# USMap.py
from Processing import *

window(700, 500)
background(0,0,100)

# Read the state data as raw text
f = open("statedata.txt", "r")
rawText = f.readlines()
f.close()

# Scale down points to fit in window
scale(0.5)

# Parse data
i = 0
while i < len(rawText) :
	
    # Convert x-y data
    pdata = rawText[i+1].split(',')
    points = [float(p) for p in pdata]
    
    # Draw state outline
    fill(255, 255, 127)
    stroke(255, 0,0)
    strokeWeight(1)

    beginShape()
    j = 0
    while j < len(points):
        vertex(points[j], points[j+1])
        j=j+2
    endShape(CLOSE)

    # Convert capital data
    stData = rawText[i].split(",")
    capital = stData[0]
    x = float(stData[3])
    y = float(stData[4])

    # Draw the capital
    stroke(0)
    strokeWeight(5)
    point(x, y)
    
    i = i + 2
