import tkinter as tk
import numpy as np

class Water:

    def __init__(self, T=4, beta=3, fd=80000, fs=20000, tau=0.1, d=1000):
        self.T = T
        self.beta = beta
        self.fd = fd
        self.fs = fs
        self.tau = tau
        self.d = d
        self.c = 1500
        self.time = np.arange(0, self.T, 1/self.fd)

    def gen_echo(self, r, phi):

        delay1 = round(2*r/self.c*self.fd)
        delay2 = round((2*r/self.c*self.fd)*self.fd)

        # s_left = np.random.randn(len(self.time))/100000000
        # s_right = np.random.randn(len(self.time))/100000000
        s_left  = np.zeros(len(self.time))
        s_right = np.zeros(len(self.time))

        for i in range(len(self.time)):
            t = self.time[i]
            A = 10**(-0.1*self.beta*r/1000)/r/r

            if t>delay1 and t<delay2:
                dt = self.d/self.c*np.sin(phi/np.pi)
                s_left[i]  += A*np.sin(2*np.pi*self.fs*self.time[i])
                s_right[i] += A*np.sin(2*np.pi*self.fs*(self.time[i] + phi))

        return [s_left, s_right]
