"""
A graphical demonstration of user-defined objects.
"""

from graphics import *
from time import *
from random import *

from sky_sun import *
from sky_cloud import *

class HotAirBalloon(object):
  """
  A class to represent a hot air balloon.
  """
  def __init__(self, where):
    """
    The constructor for the hot air balloon.  Accepts a point called where
    which will be the bottom center of the basket.
    """
    basket_ll = where.clone()
    basket_ll.move(-25,0)
    basket_ur = where.clone()
    basket_ur.move(25,50)
    self.basket = Rectangle(basket_ll, basket_ur)
    self.basket.setFill("brown")
    wire1_a = Point(basket_ll.getX(), basket_ur.getY())
    wire1_b = wire1_a.clone()
    wire1_b.move(0,50)
    self.wire1 = Line(wire1_a, wire1_b)
    wire2_a = basket_ur.clone()
    wire2_b = wire2_a.clone()
    wire2_b.move(0,50)
    self.wire2 = Line(wire2_a, wire2_b)
    balloon_center = where.clone()
    balloon_center.move(0,150)
    self.balloon = Circle(balloon_center, 60)
    self.balloon.setFill("white")
  def draw(self, win):
    self.wire1.draw(win)
    self.wire2.draw(win)
    self.basket.draw(win)
    self.balloon.draw(win)
  def move(self, x, y):
    self.basket.move(x,y)
    self.wire1.move(x,y)
    self.wire2.move(x,y)
    self.balloon.move(x,y)
  def time_to_move(self):
    if self.balloon.getCenter().getY() < 400:
      self.move(0,2)
    elif self.balloon.getCenter().getY() < 700:
      self.move(0,1)
    else:
      pass

class CloudBag(object):
  def __init__(self):
    self.clouds = []
    cloud = Cloud(Point(200,700))
    self.clouds.append(cloud)
    cloud = Cloud(Point(300,500))
    self.clouds.append(cloud)
    cloud = Cloud(Point(400,600))
    cloud.set_color("gray")
    self.clouds.append(cloud)
    cloud = Cloud(Point(400,800))
    cloud.set_color("blue")
    self.clouds.append(cloud)
  def take_cloud(self):
    i = randrange(len(self.clouds))
    cloud = self.clouds[i]
    self.clouds.remove(cloud)
    return cloud

def main():
  win = GraphWin("Sky", 1000, 1000)
  win.setCoords(0,0,1000,1000)
  win.setBackground(color_rgb(180,220,255))
  
  ground = Rectangle(Point(0,0), Point(1000,200))
  ground.draw(win)
  ground.setFill(color_rgb(0,96,0))
  
  win.getMouse()

  hot_air_balloon = HotAirBalloon(Point(425,200))
  hot_air_balloon.draw(win)
  other_balloon = HotAirBalloon(Point(575,200))
  other_balloon.draw(win)

  sun = Sun(Point(800,800))
  sun.draw(win)

  #cloud = Cloud(Point(200,700))
  #cloud.draw(win)
  #cloud2 = Cloud(Point(250,400))
  #cloud2.draw(win)
  #cloud2.set_color("gray")
  bag = CloudBag()
  for i in range(2):
    cloud = bag.take_cloud()
    cloud.draw(win)

  win.getMouse()

  for n in range(800):
    hot_air_balloon.time_to_move()
    sleep(0.01)

  win.getMouse()
  
main()
