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

def make_diamond(where, size, color):
  p1 = where.clone()
  p1.move(0,-size)
  p2 = where.clone()
  p2.move(0,size)
  p3 = where.clone()
  p3.move(size,0)
  p4 = where.clone()
  p4.move(-size,0)
  polygon = Polygon(p1,p3,p2,p4)
  polygon.setFill(color)
  return polygon

def random_diamond(width, height):
  x = randrange(width)
  y = randrange(height)
  size = randrange(20,100)
  diamond = make_diamond(Point(x,y), size, "blue")
  return diamond

def main():
  width = 800
  height = 800
  window = GraphWin("Diamonds", width, height)
  window.setBackground("green")
  # Make a bunch of diamonds and draw them
  all_of_my_diamonds = []
  for n in range(20):
    diamond = random_diamond(width, height)
    all_of_my_diamonds.append(diamond)
    diamond.draw(window)
  window.getMouse()
  # Take the diamonds away
  for i in range(50):
    for diamond in all_of_my_diamonds:
      diamond.move(0,4)
    sleep(0.2)
  #for diamond in all_of_my_diamonds:
  #  diamond.undraw()
  window.getMouse()

main()
