from pyg import *

class PygBubble(Pyg):
    def __init__(self,w,h,fps,name):
        Pyg.__init__(self,w,h,fps,name)
    
    def drawRay(self,bubble,color):
        x,y = bubble.x,bubble.y
        self.drawCircle(x,y,bubble.r,color)

    def drawForce(self,bubble,color):
        x1,y1 = bubble.x,bubble.y
        vx,vy = bubble.getForceVector()
        x2 = x1+vx*bubble.r
        y2 = y1+vy*bubble.r
        self.drawLine(x1,y1,x2,y2,color)

    def drawDirection(self,bubble,color):
        x1,y1 = bubble.x,bubble.y
        dirx,diry = bubble.direction
        x2 = x1+dirx*bubble.r
        y2 = y1+diry*bubble.r
        self.drawLine(x1,y1,x2,y2,color)

    def drawBubble(self,bubble):
        self.drawRay(bubble,(128,128,255))
        self.drawForce(bubble,(255,128,192))
        self.drawDirection(bubble,(128,128,128))
        for child in bubble.getChild():
            self.drawBubble(child)
        for link in bubble.link:
            x1,y1 = bubble.x,bubble.y
            x2,y2 = link.x,bubble.y
            self.drawLine(x1,y1,x2,y2,(255,255,128))
            self.drawBubble(link)

    def drawAll(self,pool):
        for bubble in pool.values():
            self.drawBubble(bubble)
                
