Hi, sorry for such a beginner's question, but I've only been using Python
for a couple of weeks, and almost entirely figuring out Keras.
But I already love Pyqt, and thanks for developing such a great package. I
think this will be a really simple one, but could anyone advise a sensible
way to write this?
This runs a simple animated Langton's Ant demo, but very slowly, because
every update I'm using view.addItem – which is surely not the best way to
plot real-time pixels. But very simple to write and look at. Thanks so much
– this has been driving me slightly crazy.
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph as pg
import sys
direction = 1
x = 250
y = 250
app = QtGui.QApplication([])
w = pg.GraphicsView()
w.show()
w.resize(500,500)
w.setWindowTitle('Ant demo')
view = pg.ViewBox()
w.setCentralItem(view)
view.setAspectLocked(True)
screen = np.zeros((500,500))
img = pg.ImageItem(screen)
view.addItem(img)
img.setLevels([0, 1])
def update():
global screen, img, x, y, direction, w
hello = screen[x,y]
if hello == 1:
direction += 1
screen[x,y] = 0
else:
direction -= 1
screen[x,y] = 1
if direction == 0:
direction = 4
if direction == 5:
direction = 1
if direction == 1:
y -= 1
elif direction == 2:
x += 1
elif direction == 3:
y += 1
elif direction == 4:
x -= 1
img = pg.ImageItem(screen)
view.addItem(img)
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(1)
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/47d8c765-6bcf-48a6-b9ef-29af7edbb585%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.