# This program demonstrates some of Python's graphics capabilities

from graphics import *
import random, time

def bubbles():

    colorNames = ['red', 'yellow', 'blue', 'green', 'orange']

    # create the drawing window
    win = GraphWin("Bubbles", 400, 400)

    num = input("How many bubbles would you like? ")

    # keep track of the bubble objects already created
    bubs = []

    for i in range(num):
        # choose a random center point
        x = random.randrange(400)
        y = random.randrange(400)
        center = Point(x, y)
        # choose a random radius
        radius = random.randrange(20, 70)
        # create the bubble object
        circ = Circle(center, radius)

        # choose a color
        color = colorNames[i % 5]
        circ.setFill(color)

        # draw the bubble
        circ.draw(win)
        print "circle of radius", radius, "at", x, y

        # add the bubble to the bubs list
        bubs.append(circ)

        # make all existing bubbles move at random a little
        for b in bubs:
            dx = random.randrange(-3, 4)
            dy = random.randrange(-3, 4)
            b.move(dx, dy)
            # pause for 1/100th of a second
            time.sleep(0.01)

        # make a random bubble disappear
        b = random.choice(bubs)
        b.undraw()
