Advertisement
Chl_Snt

Sin

May 13th, 2023
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. import math
  2. import sys
  3.  
  4. from PyQt5.QtCore import Qt
  5. from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QSlider
  6. from PyQt5.QtChart import QChart, QChartView, QLineSeries
  7. from numpy import arange
  8.  
  9.  
  10. class Window(QWidget):
  11.     def __init__(self):
  12.         super().__init__()
  13.         self.setGeometry(200, 200, 600, 400)
  14.         self.setWindowTitle("График пиццы")
  15.         self.k = 1
  16.  
  17.         self.series = QLineSeries()
  18.         for x in arange(-10, 10, 0.003):
  19.             y = math.sin(self.k * x)
  20.             self.series.append(x, y)
  21.  
  22.         chart = QChart()
  23.         chart.addSeries(self.series)
  24.         chart.setAnimationOptions(QChart.SeriesAnimations)
  25.         chart.setTitle("Синусоида")
  26.         chart.setTheme(QChart.ChartThemeBlueCerulean)
  27.         chart.createDefaultAxes()
  28.  
  29.         chartview = QChartView(chart)
  30.  
  31.         vbox = QVBoxLayout()
  32.         sld = QSlider(Qt.Horizontal, self)
  33.  
  34.         sld.valueChanged[int].connect(self.changeValue)
  35.         vbox.addWidget(chartview)
  36.         vbox.addWidget(sld)
  37.         self.setLayout(vbox)
  38.  
  39.     def changeValue(self, k):
  40.         self.k = k / 10
  41.         self.series.clear()
  42.         for x in arange(-10, 10, 0.003):
  43.             y = math.sin(self.k * x)
  44.             self.series.append(x, y)
  45.  
  46.  
  47. App = QApplication(sys.argv)
  48. window = Window()
  49. window.show()
  50. sys.exit(App.exec())
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement