You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
7 years ago
|
from PyQt4 import QtCore, QtGui, Qt
|
||
|
from PyQt4.QtGui import QApplication, QMainWindow
|
||
|
import sys, math
|
||
|
|
||
|
class MyMainScreen(QMainWindow):
|
||
|
def __init__(self, parent=None):
|
||
|
QtGui.QMainWindow.__init__(self, parent)
|
||
|
|
||
|
self.timer = QtCore.QTimer(self)
|
||
|
self.timer.setInterval(100)
|
||
|
self.timer.timeout.connect(self.blink)
|
||
|
self.timer.start()
|
||
|
|
||
|
self.resize(500, 500)
|
||
|
self.centralwidget = QtGui.QWidget(self)
|
||
|
self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget)
|
||
|
|
||
|
self.setCentralWidget(self.centralwidget)
|
||
|
self.menubar = QtGui.QMenuBar(self)
|
||
|
self.menubar.setGeometry(QtCore.QRect(0, 0, 500, 22))
|
||
|
|
||
|
self.setMenuBar(self.menubar)
|
||
|
|
||
|
self.statusbar = QtGui.QStatusBar(self)
|
||
|
self.setStatusBar(self.statusbar)
|
||
|
QtCore.QMetaObject.connectSlotsByName(self)
|
||
|
|
||
|
self.n = 0
|
||
|
|
||
|
def blink(self):
|
||
|
self.n += 0.1
|
||
|
self.n = self.n % 20
|
||
|
self.repaint()
|
||
|
|
||
|
def paintEvent(self, event):
|
||
|
painter = QtGui.QPainter(self)
|
||
|
painter.setRenderHint(QtGui.QPainter.Antialiasing)
|
||
|
painter.setRenderHint(QtGui.QPainter.HighQualityAntialiasing)
|
||
|
painter.setPen(QtGui.QPen(QtCore.Qt.red, 2))
|
||
|
|
||
|
step = 2
|
||
|
amp = (self.height()/2)*0.8
|
||
|
for i in range(0, self.width(), step):
|
||
|
y0 = round(self.height()/2 + amp * math.sin(2*math.pi*self.n*(i/180)))
|
||
|
y1 = round(self.height()/2 + amp * math.sin(2*math.pi*self.n*((i+step)/180)))
|
||
|
painter.drawLine(QtCore.QLine(i, y0, i+step, y1))
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
app = QApplication(sys.argv)
|
||
|
mainscreen = MyMainScreen()
|
||
|
mainscreen.show()
|
||
|
app.exec_()
|