"""
------------------------------------------------------------------------------
--                                                                          --
--                                 LAB 05                                   --
--                                                                          --
--                  A S T E R I S K _ D I A M O N D . P Y                   --
--                                                                          --
------------------------------------------------------------------------------
-- <Your Name Here>                                                         --
--                                                                          --
-- CISC106 011 Spring 2013                                                  --
--                                                                          --
------------------------------------------------------------------------------
-- This file contains a demo which will draw an expanding and contracting   --
-- diamond made out of asterisks.                                            --
--                                                                          --
------------------------------------------------------------------------------
"""

from tkinter import *
from lab05 import *

class DiamondFrame(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master, width=500)
        Pack.config(self)
        self.count = 0
        self.increment = 1

        self.nw = StringVar()
        self.ne = StringVar()
        self.sw = StringVar()
        self.se = StringVar()

        Label(self, textvariable=self.nw, anchor=SE, justify=RIGHT).grid(row=0, column=0)
        Label(self, textvariable=self.ne, anchor=SW, justify=LEFT).grid(row=0, column=1)
        Label(self, textvariable=self.sw, anchor=NE, justify=RIGHT).grid(row=1, column=0)
        Label(self, textvariable=self.se, anchor=NW, justify=LEFT).grid(row=1, column=1)

        self.after(10, DiamondFrame.update, self)

    def update(self):
        if self.count == 25:
            self.increment = -1
        elif self.count == 1:
            self.increment = 1

        self.count += self.increment

        self.nw.set(backward_asterisk_triangle(self.count))
        self.ne.set(asterisk_triangle(self.count))
        self.sw.set(backward_upside_down_asterisk_triangle(self.count))
        self.se.set(upside_down_asterisk_triangle(self.count))

        self.after(42, DiamondFrame.update, self)

if __name__ == '__main__':
    root = Tk()
    root.title('Asterisk Diamond')
    root.minsize(310,710)
    outer = Frame(root, width=310, height=710)
    outer.pack(fill='both', expand=True)
    inner = DiamondFrame()
    inner.place(in_=outer, anchor="c", relx=0.5, rely=0.5)
    inner.mainloop()
