# PieChart2.py
from Processing import *

data = [48.32, 19.81, 18.43, 6.42, 1.4, 1.34]
colors = [ color(214, 13, 50), color(13, 21, 214),
           color(190, 13, 214), color(190, 214, 13),
           color(13, 214, 21), color(13, 214, 189)  ]

window(500, 500)
background(255)

# Center and size of chart
x = width()/2 - 100
y = height()/2
w = 200

# Init Legend
kx = x + 0.75*w
ky = y - 0.5*w
kw = 20
ks = 10
angle = 0

i = 0
while i < len(data):
    # Draw the ith Pie
    theta = angle + data[i]*2*PI/100
    fill(colors[i])
    arc(x, y, w, w, angle, theta)
    angle = theta
    
    ky = ky + 2*kw
    rect(kx, ky, kw, kw)
    fill(0)
    label = "Slice %s" % (i+1)
    text(label, kx+kw+ks, ky+kw)

    i += 1
