-
Notifications
You must be signed in to change notification settings - Fork 0
/
figure8.py
135 lines (103 loc) · 3.82 KB
/
figure8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import math
import sys
from PySide2 import QtWidgets, QtGui, QtCore
class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Widget, self).__init__(parent)
self.setWindowTitle('Test Application')
self.valueFigure8 = 250
self.valueEllipse = 250
self.changeFigure8 = False
self.changeEllipse = False
def sizeHint(self):
return QtCore.QSize(600, 600)
def paintEvent(self, event):
items = []
for i in range(64):
items.append(i)
painter = QtGui.QPainter(self)
painter.setWindow(QtCore.QRect(-300, -300, 600, 600))
# self.drawEllipse(painter)
self.drawFigure8(painter)
self.drawEllipse(painter)
@QtCore.Slot(bool)
def updateFigure8(self, status):
self.changeFigure8 = status
@QtCore.Slot(bool)
def updateEllipse(self, status):
self.changeEllipse = status
@QtCore.Slot(int)
def setValue(self, value):
if self.changeFigure8:
self.valueFigure8 = value
if self.changeEllipse:
self.valueEllipse = value
if self.changeEllipse or self.changeFigure8:
self.update()
def drawEllipse(self, painter):
ellipseState = []
for i in range(64):
ellipseState.append(QtCore.QPointF(math.cos((i / 63.0) * 6.28) * self.valueEllipse,
math.sin((i / 63.0) * 6.28) * self.valueEllipse))
path = QtGui.QPainterPath()
path.moveTo(ellipseState[0])
for i in range(1, 64):
path.lineTo(ellipseState[i])
# print(f'{i}. {ellipseState[i]}')
# painter.drawPoint(ellipseState[i])
painter.setPen(QtGui.QPen(QtCore.Qt.red, 2))
painter.drawPath(path)
def drawFigure8(self, painter):
figure8State = []
for i in range(64):
# figure8State.append(QtCore.QPointF(math.sin((i / 63.0) * 6.28) * 250,
# math.sin(((i * 2)/63.0) * 6.28) * 250))
figure8State.append(QtCore.QPointF(math.sin((i / 63.0) * 6.28) * self.valueFigure8,
math.sin(((i * 2)/63.0) * 6.28) * self.valueFigure8))
path = QtGui.QPainterPath()
path.moveTo(figure8State[0])
for i in range(1, 64):
path.lineTo(figure8State[i])
painter.setPen(QtGui.QPen(QtCore.Qt.blue, 2))
painter.drawPath(path)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
pal = QtGui.QPalette()
print(pal.color(QtGui.QPalette.Active, QtGui.QPalette.Window))
window = Widget()
slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
slider.setRange(1, 400)
slider.setValue(250)
slider.valueChanged.connect(window.setValue)
elipseCBox = QtWidgets.QCheckBox('Ellipse')
elipseCBox.stateChanged.connect(window.updateEllipse)
figure8CBox = QtWidgets.QCheckBox('Figure 8')
figure8CBox.stateChanged.connect(window.updateFigure8)
gview = QtWidgets.QGraphicsView()
scene = QtWidgets.QGraphicsScene()
scene.setBackgroundBrush(QtGui.QBrush(pal.color(QtGui.QPalette.Active, QtGui.QPalette.Window)))
gview.setScene(scene)
# gview.setBackgroundBrush(QtGui.QBrush(pal.color(QtGui.QPalette.Active, QtGui.QPalette.Window)))
# gview.setBackgroundBrush(QtGui.QBrush(QtCore.Qt.black))
layout = QtWidgets.QVBoxLayout()
layout.addWidget(window)
layout.addWidget(slider)
layout.addWidget(elipseCBox)
layout.addWidget(figure8CBox)
layout.addWidget(gview)
mainWindow = QtWidgets.QWidget()
mainWindow.setLayout(layout)
mainWindow.show()
sys.exit(app.exec_())
# # Figure 8.
# figure8State.assignProperty(item, 'pos',
# QtCore.QPointF(math.sin((i / 63.0) * 6.28) * 250,
# math.sin(((i * 2)/63.0) * 6.28) * 250))
# # Random.
# randomState.assignProperty(item, 'pos',
# QtCore.QPointF(-250 + QtCore.qrand() % 500,
# -250 + QtCore.qrand() % 500))
# # Tiled.
# tiledState.assignProperty(item, 'pos',
# QtCore.QPointF(((i % 8) - 4) * kineticPix.width() + kineticPix.width() / 2,
# ((i // 8) - 4) * kineticPix.height() + kineticPix.height() / 2))