"""
This file defines a class to represent a cloud in a graphical scene.
"""

from graphics import *

class Cloud(object):
  """
  A class to represent a cloud in a graphical scene.
  """
  def __init__(self, where):
    """
    Creates a new cloud.  The parameter where defines the location of the
    cloud's approximate center.
    """
    bottom_of_cloud_ll = where.clone()
    bottom_of_cloud_ll.move(-80,-40)
    bottom_of_cloud_ur = where.clone()
    bottom_of_cloud_ur.move(80,40)
    self.bottom_of_cloud = Rectangle(bottom_of_cloud_ll, bottom_of_cloud_ur)
    self.bottom_of_cloud.setFill("white")
    self.bottom_of_cloud.setOutline("white")
    # Now let's put some circles all over the rectangle to make it puffy
    self.circles = [
      self.make_white_circle(where, -80, 0, 40),
      self.make_white_circle(where, 80, 0, 40),
      self.make_white_circle(where, -60, 30, 40),
      self.make_white_circle(where, -30, 30, 30),
      self.make_white_circle(where, -10, 40, 30),
      self.make_white_circle(where, 10, 30, 30),
      self.make_white_circle(where, 40, 40, 40),
      self.make_white_circle(where, 60, 20, 20)
      ]
  def make_white_circle(self, where, dx, dy, radius):
    """
    A helper routine to make writing the constructor easier.
    """
    center = where.clone()
    center.move(dx,dy)
    circle = Circle(center, radius)
    circle.setFill("white")
    circle.setOutline("white")
    return circle
  def draw(self, win):
    self.bottom_of_cloud.draw(win)
    for circle in self.circles:
      circle.draw(win)
  def move(self,x,y):
    for obj in self.circles:
      obj.move(x,y)
    self.bottom_of_cloud.move(x,y)
  def set_color(self, color):
    for obj in self.circles:
      obj.setFill(color)
      obj.setOutline(color)
    self.bottom_of_cloud.setFill(color)
    self.bottom_of_cloud.setOutline(color)
  def time_to_move(self):
    self.move(1,0)
