def __init__(self, master):
        self.pendulo = Pendulum()
        self.pendulo.Phi = math.radians(45)
        self.controlador = ControladorPendulo()

        w = Canvas(master, width=800, height=400)
        self.w = w
        w.pack()

        #creamos el piso
        w.create_polygon(0, 270, 800, 270, 800, 300, 0, 300, fill='black')

        self.carga = w.create_oval(0, 0, 10, 10, fill='red')
        self.pivote = w.create_line(0, 0, 400, 300)  # x0, y0, x1, y1
        self.carro = w.create_polygon(0, 0, 70, 0, 70, 30, 0, 30, fill='blue')

        self.actualizar_puntos()
        self.posicionar_objetos()

        frame = Frame(master)
        frame.pack()

        self.iniciar = Button(frame, text="Iniciar", command=self.iniciar)
        self.iniciar.pack(side=LEFT)
        self.detener = Button(frame, text="Detener", command=self.detener)
        self.detener.pack(side=LEFT)
        self.paso = Button(frame, text="Paso", command=self.hacer_paso)
        self.paso.pack(side=LEFT)

        self.lx = StringVar()
        Label(frame, text="X: ").pack(side=LEFT)
        Label(frame, textvariable=self.lx).pack(side=LEFT)

        self.ldx = StringVar()
        Label(frame, text="dX: ").pack(side=LEFT)
        Label(frame, textvariable=self.ldx).pack(side=LEFT)

        self.lphi = StringVar()
        Label(frame, text="Phi: ").pack(side=LEFT)
        Label(frame, textvariable=self.lphi).pack(side=LEFT)

        self.ldphi = StringVar()
        Label(frame, text="dPhi: ").pack(side=LEFT)
        Label(frame, textvariable=self.ldphi).pack(side=LEFT)

        self.la = StringVar()
        Label(frame, text="Aceleracion: ").pack(side=LEFT)
        Label(frame, textvariable=self.la).pack(side=LEFT)
class MuestraPendulo:

    def __init__(self, master):
        self.pendulo = Pendulum()
        self.pendulo.Phi = math.radians(45)
        self.controlador = ControladorPendulo()

        w = Canvas(master, width=800, height=400)
        self.w = w
        w.pack()

        #creamos el piso
        w.create_polygon(0, 270, 800, 270, 800, 300, 0, 300, fill='black')

        self.carga = w.create_oval(0, 0, 10, 10, fill='red')
        self.pivote = w.create_line(0, 0, 400, 300)  # x0, y0, x1, y1
        self.carro = w.create_polygon(0, 0, 70, 0, 70, 30, 0, 30, fill='blue')

        self.actualizar_puntos()
        self.posicionar_objetos()

        frame = Frame(master)
        frame.pack()

        self.iniciar = Button(frame, text="Iniciar", command=self.iniciar)
        self.iniciar.pack(side=LEFT)
        self.detener = Button(frame, text="Detener", command=self.detener)
        self.detener.pack(side=LEFT)
        self.paso = Button(frame, text="Paso", command=self.hacer_paso)
        self.paso.pack(side=LEFT)

        self.lx = StringVar()
        Label(frame, text="X: ").pack(side=LEFT)
        Label(frame, textvariable=self.lx).pack(side=LEFT)

        self.ldx = StringVar()
        Label(frame, text="dX: ").pack(side=LEFT)
        Label(frame, textvariable=self.ldx).pack(side=LEFT)

        self.lphi = StringVar()
        Label(frame, text="Phi: ").pack(side=LEFT)
        Label(frame, textvariable=self.lphi).pack(side=LEFT)

        self.ldphi = StringVar()
        Label(frame, text="dPhi: ").pack(side=LEFT)
        Label(frame, textvariable=self.ldphi).pack(side=LEFT)

        self.la = StringVar()
        Label(frame, text="Aceleracion: ").pack(side=LEFT)
        Label(frame, textvariable=self.la).pack(side=LEFT)

    def posicionar_objetos(self):
        cax, cay = self.pto_carga
        cox, coy = self.pto_carro
        self.w.coords(self.pivote, cax, cay, cox, coy - 15)
        self.w.coords(self.carga, cax - 15, cay - 15, cax + 15, cay + 15)
        self.w.coords(self.carro, cox - 35, coy, cox + 35, coy,
                                  cox + 35, coy - 30, cox - 35, coy - 30)

    def _coord(self, x, y):
        return (x + 400, 270 - y)

    def actualizar_puntos(self):
        escala = 100
        cox = self.pendulo.X * escala
        coy = 0

        phi = self.pendulo.Phi
        l = self.pendulo.l * escala

        cax = cox + l * math.cos(phi)
        cay = l * math.sin(phi)

        self.pto_carro = self._coord(cox, coy)
        self.pto_carga = self._coord(cax, cay)

    def hacer_paso(self):
        aceleracion = self.controlador.compute(
                               phi=int(math.degrees(self.pendulo.Phi)),
                               dphi_dt=int(math.degrees(self.pendulo.dPhi_dT)),
                               dx_dt=int(self.pendulo.dX_dT),
                               x=int(self.pendulo.X),
                               a=int(self.pendulo.a))
        self.lx.set("%6.2f" % self.pendulo.X)
        self.ldx.set("%6.2f" % self.pendulo.dX_dT)
        self.lphi.set("%6.2f" % math.degrees(self.pendulo.Phi))
        self.ldphi.set("%6.2f" % math.degrees(self.pendulo.dPhi_dT))
        self.la.set("%6.2f" % aceleracion)
        self.pendulo.a = aceleracion
        self.pendulo.doStep(0.01)
        self.actualizar_puntos()
        self.posicionar_objetos()

    def iniciar(self):
        print 'inicia'
        self.timer = PerpetualTimer(0.01, self.hacer_paso)
        self.timer.start()

    def detener(self):
        print 'detiene'
        self.timer.cancel()