import sys 
from PyQt5 import QtWidgets,QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QSizePolicy, QMessageBox, QWidget, QPushButton
from PyQt5.QtGui import QIcon
import design  
import requests
import qdarkstyle
import os
import math
import ctypes
import random
import seaborn as sns
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
plt.ion()
V0=10 #Нач скорость
a=45 #Угол
m=1 #Масса
k=1 #Коэфф сопротивления воздуха
 
class ExampleApp(QtWidgets.QMainWindow, design.Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self) 
        self.setWindowIcon(QIcon('science.png')) 
        m = PlotCanvas(self, width=7, height=5.5)
        m.move(400,10)
        self.pushButton.clicked.connect(self.draw1)
 
    def draw1(self):
        global V0
        V0=100
        PlotCanvas()
        
        
class PlotCanvas(FigureCanvas):
 
    def __init__(self, parent=None, width=5, height=4, dpi=100):
        fig = Figure(figsize=(width, height), dpi=dpi)
        FigureCanvas.__init__(self, fig)
        self.setParent(parent)
        rect = fig.patch 
        rect.set_facecolor('#19232d')
        fig.clear()
        FigureCanvas.setSizePolicy(self,
                QSizePolicy.Expanding,
                QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)
        self.plot()
 
    def Lenght(self,V0, a, m, k): #Расчёт траектории (совокупность координат (x,y) )
        print(V0, a, m, k)
        V_x = [V0 * math.cos(a * math.pi / 180)]
        V_y = [V0 * math.sin(a * math.pi / 180)]
        x_m = [0]
        y = [0]
        i = 0
        dt = 0.0001
        g = 9.8195
        while y[i] >= 0:
            V_x.append(V_x[i] - k * V_x[i] * dt / 1)
            V_y.append(V_y[i] - (g + k * V_y[i] / 1) * dt)
            x_m.append(x_m[i] + V_x[i] * dt)
            y.append(y[i] + V_y[i] * dt)
            i += 1
        return x_m, y
    def plot(self):
        global V0, a, m, k,line1
        x_m, y = self.Lenght(V0, a, m, k) 
        ax = self.figure.add_subplot(111) 
        #Косметика графика
        rect = ax.patch
        rect.set_facecolor('#19232d')
        ax.grid()  
        ax.tick_params(axis='x', colors='white')
        ax.tick_params(axis='y', colors='white')
        ax.set_xlabel('Путь', fontsize=20, color='#778899')
        ax.set_ylabel('Высота', fontsize=20, color='#778899')
       #Отрисовка
        ax.plot(x_m, y, color="#ffab03")
       
        self.draw()
        print(1)
 
def main():
    app = QtWidgets.QApplication(sys.argv)  
    window = ExampleApp()  
    app.setStyleSheet(qdarkstyle.load_stylesheet(qt_api='pyqt5'))
    window.show()  
    app.exec_()  
 
if __name__ == '__main__':  
    main()
