I have something like graph and i have a trouble. I need to draw snowman, which moves on cosine trajectory.
import sys
import math
import time
from PyQt4 import QtGui, QtCore
class MyFrame(QtGui.QGraphicsView):
def __init__( self, parent = None ):
super(MyFrame, self).__init__(parent)
self.resize(800,600)
scene = QtGui.QGraphicsScene()
self.setScene(scene)
for x in range(100):
y = 100*(math.cos(x+200))
pen1 = QtGui.QPen(QtGui.QColor(QtCore.Qt.red))
brush1 = QtGui.QBrush(pen1.color().darker(255))
item1 = scene.addEllipse(x, y, 100, 100, pen1,brush1)
pen2 = QtGui.QPen(QtGui.QColor(QtCore.Qt.green))
brush2 = QtGui.QBrush(pen2.color().darker(150))
item2 = scene.addEllipse(x-25, y+100, 150, 150, pen2,brush2)
pen3 = QtGui.QPen(QtGui.QColor(QtCore.Qt.blue))
brush3 = QtGui.QBrush(pen3.color().darker(150))
item3 = scene.addEllipse(x-50, y+250, 200, 200, pen3,brush3)
time.sleep(3)
app = QtGui.QApplication([])
f = MyFrame()
f.show()
app.exec_()
Now i have some questions.
When i use time.sleep(2)
, it's just wait for a few seconds and show me final result without steps.
1) What i need to do for fixing it?
2) What i need to do for situation, when it looks like moving animation?
I tried to use QPoint, but it is a few hard to use in my code, i have no experience and i believe, that this problem solves more easier.