# L-33 MCS 260 Monday 6 April 2015 : class_showparabola
"""
To show a parabola on canvas, we extend the object parabola with a canvas
and a method to draw the parabola on canvas.
"""
from tkinter import Tk, Canvas
from math import pi
from random import randint, uniform
from class_parabola import Parabola
from class_showline import ShowLine

class ShowParabola(Parabola, ShowLine):
    """
    Extends the Parabola class with a draw method.
    """
    def __init__(self, c, d, x, y, a, fx, fy):
        """
        Defines the parabola with directrix the line
        at base point (x, y), angle a, and the focus
        with coordinates (fx, fy).
        Stores the canvas c of dimension d.
        """
        Parabola.__init__(self, x, y, a, fx, fy)
        ShowLine.__init__(self, c, d, x, y, a)

    def draw_focus(self):
        """
        Draws the focus on canvas.
        """
        (fxp, fyp) = (self.focus.xpt, self.focus.ypt)
        self.canvas.create_oval(fxp-3, \
            fyp-3, fxp+3, fyp+3, fill='SkyBlue2')

    def draw(self):
        """
        Draws the parabola on canvas.
        """
        ShowLine.draw(self)
        self.draw_focus()
        for tpt in range(-1000, 1000):
            prb = Parabola.__call__(self, tpt)
            self.canvas.create_oval(prb.xpt-1, \
                prb.ypt-1, prb.xpt+1, prb.ypt+1, \
                fill='SkyBlue2')

def main():
    """
    Draws one parabola
    """
    top = Tk()
    dim = 400
    cnv = Canvas(top, width=dim, height=dim)
    cnv.pack()
    (xbs, ybs) = (randint(6, dim-6), randint(6, dim-6))
    agl = uniform(0, 2*pi)
    (fpx, fpy) = (randint(6, dim-6), randint(6, dim-6))
    pbl = ShowParabola(cnv, dim, xbs, ybs, agl, fpx, fpy)
    pbl.draw()
    top.mainloop()

if __name__ == "__main__":
    main()
