Beispiel #1
0
 def set_number_of_circles(self, *event: tk.Event) -> None:
     """
     Set the number of circles.
     """
     resolution = self.circles_slider.get()
     self._number_of_circles = resolution
     FourierAnimation.set_number_of_circles(self, resolution + 1)
class Canvas(FigureCanvasQTAgg):
    """
    The canvas.
    """

    def __init__(self,
                 parent: QtWidgets.QMainWindow,
                 rect: QtCore.QRect) -> None:
        """
        The constructor.

        Parameters:
         parent: The parent widget that this
         canvas is being created from
         rect: used to get information
         about the screen width and screen height.
        """
        width = rect.width()
        dpi = int(150*width//1920)
        self._parent = parent
        self._ani = FourierAnimation("3*rect(t)/2", dpi)
        self._ani.set_speed(1)
        FigureCanvasQTAgg.__init__(self, self._ani.figure)
        self.setMinimumHeight(400)
        self.setMinimumWidth(int(width*0.75))
        self._mouse_usage = 0
        self._prev_mouse_position = []

    def get_animation(self):
        """
        Getter for the animation object.

        Returns:
         The animation object.
        """
        return self._ani

    def animation_loop(self) -> None:
        """
        Do the main animation loop.
        """
        self._ani.animation_loop()
Beispiel #3
0
    def __init__(self) -> None:
        """
        The constructor.
        """
        self.window = tk.Tk()
        self.window.title("Visualization of Fourier Series")
        width = self.window.winfo_screenwidth()
        dpi = int(150 * width // 1920)
        FourierAnimation.__init__(self, "3*rect(t)/2", dpi)

        # Thanks to StackOverflow user rudivonstaden for
        # giving a way to get the colour of the tkinter widgets:
        # https://stackoverflow.com/questions/11340765/
        # default-window-colour-tkinter-and-hex-colour-codes
        #
        #     https://stackoverflow.com/q/11340765
        #     [Question by user user2063:
        #      https://stackoverflow.com/users/982297/user2063]
        #
        #     https://stackoverflow.com/a/11342481
        #     [Answer by user rudivonstaden:
        #      https://stackoverflow.com/users/1453643/rudivonstaden]
        #
        colour = self.window.cget('bg')
        if colour == 'SystemButtonFace':
            colour = "#F0F0F0"
        # Thanks to StackOverflow user user1764386 for
        # giving a way to change the background colour of a plot.
        #
        #    https://stackoverflow.com/q/14088687
        #    [Question by user user1764386:
        #     https://stackoverflow.com/users/1764386/user1764386]
        #
        try:
            self.figure.patch.set_facecolor(colour)
        except ValueError:
            print(colour)

        self.canvas = backend_tkagg.FigureCanvasTkAgg(self.figure,
                                                      master=self.window)
        self.canvas.get_tk_widget().grid(row=1,
                                         column=0,
                                         rowspan=8,
                                         columnspan=3)
        self.function_dropdown_dict = {
            "sine": "sin(t)",
            "cosine": "cos(t)",
            "gaussian": "3*exp(-t**2/(2*sigma**2 ))/2 - 1/2",
            "sinc": "3*sinc(k*(6.5)*t)/2 - 1/2",
            "rectangle": "3*rect(t)/2",
            "sawtooth": "t/pi",
            "triangle": "abs(t)"
        }
        self.function_dropdown_string = tk.StringVar(self.window)
        self.function_dropdown_string.set("Preset Waveform f(t)")
        self.function_dropdown = tk.OptionMenu(
            self.window,
            self.function_dropdown_string,
            *tuple(key for key in self.function_dropdown_dict),
            command=self.set_function_dropdown)
        self.function_dropdown.grid(row=2,
                                    column=3,
                                    padx=(10, 10),
                                    pady=(0, 0))

        self.enter_function_label = tk.Label(
            self.window,
            text="Enter waveform f(t)",
        )
        self.enter_function_label.grid(row=3,
                                       column=3,
                                       sticky=tk.S + tk.E + tk.W,
                                       padx=(10, 10),
                                       pady=(0, 0))
        self.enter_function = tk.Entry(self.window)
        self.enter_function.grid(row=4,
                                 column=3,
                                 sticky=tk.N + tk.E + tk.W + tk.S,
                                 padx=(10, 10))
        self.enter_function.bind("<Return>", self.set_function_entry)
        self.update_button = tk.Button(self.window,
                                       text='OK',
                                       command=self.set_function_entry)
        self.update_button.grid(row=5,
                                column=3,
                                sticky=tk.N + tk.E + tk.W,
                                padx=(10, 10),
                                pady=(0, 0))
        self.sliderslist = []
        self.circles_slider = None
        self.slider_speed = None
        self._speed = 1
        self.quit_button = None
        self._number_of_circles = 80
        self._set_widgets_after_param_sliders()
Beispiel #4
0
from animation import FourierAnimation
from test_logo import *

anim = FourierAnimation(youtube, size=(800, 600), title="Steve28 : Youtube Fourier Drawing", teleport=0)
anim.start()