#__________________________________________________________________________
#2.py
 
# This example is the same as the previous (Matilda, 1.py) but
# we'll use LISTS instead of strings
 
# A Python LIST is also a "sequence",like a string, but it is more
# general and flexible than a string. It is mutable, i.e., you can
# change its elements. You can also apply all the string operations
# to a list. Just like you'll learn string methods (yes, strings are
# objects) you'll also learn list methods, because lists are also objects.
 
# Note: We are keeping month and foodgroup information in LISTS.
# First advantage -> we don't have to limit item sizes because of the second advantage
# Second advantage -> we can index into a list without slicing
 
# You'll notice that nearly all the code remains the same except for
# month and foodgroup information (now LISTS), and how we index into
# this information to get what we want. We've left the color information
# in a string (we could have changed that too, but since the indexing there
# was like a list index, we left it unchanged)
 
 
from graphics import *
 
def wait():
    x = input(" ")
    return
 
 
def box(m,cstring,botleftx,botlefty,w):
    s = Rectangle(Point(botleftx,botlefty),Point(botleftx+12,botlefty+1))
 
    p = (12-m)*1
    code = cstring[p:p+1]  #still slicing thru color string in this example 
 
    c = "blue"
    if (code == "R"):      # We'll see a better way to
        c = "red"
    if (code == "G"):      # check for diferent possibilities
        c = "green"
    if  (code == "Y"):     # later
        c = "yellow"
 
    s.draw(w)     # we're going to draw the box, and then
 
    wait()
    s.setFill(c)  # fill it with the right color
    wait()
 
    lin = Line(Point(botleftx+5,botlefty),Point(botleftx+5,botlefty+1))
    lin.draw(w)

    return
 
def month(n,mlist,botleftx,w):
 
    t = Text(Point(botleftx+3,13-n+0.5),mlist[n-1])
    t.setSize(18)
    t.setStyle("bold")
    t.draw(w)

    return
 
 
def food(n,flist,botleftx,w):
 
    t = Text(Point(botleftx+8,13-n+0.5),flist[n-1])
    t.setSize(18)
    t.setStyle("bold")
    t.draw(w)

    return
 
 
def main():
 
 
    w = GraphWin("Waltzing Matilda's Weightloss Plan",300,600)
 
    w.setCoords(0,0,14,14)
 
    r = Rectangle(Point(1,1),Point(13,13))
    r.setWidth(3)
    r.draw(w)
 
    monthlist = ["January", "February", "March", "April",
                 "May", "June", "July", "August",
                 "September", "October", "November", "December"]
 
    foodlist = ["Carrots", "Beans", "Broccoli", "Beets",
                "Spinach", "Potatoes", "Chard", "Asparagus",
                "Cauliflower", "Yams", "Turnips", "Cakes"]
 
    colorstring = "RGGRGYGGYRYG"
 
    for j in range(1,13,1):
        wait()
        box(j,colorstring,1,1+j-1,w)
        wait()
        month(13-j,monthlist,1,w)
        wait()
        food(13-j,foodlist,1,w)

    return        
#_________________________________________________________________________
main()
