p.drawLine(line) self.pen.setColor(Qt.blue) p.setPen(self.pen) for line in self.lines[self.num_of_lines_generations_back[2]: self.num_of_lines_generations_back[1]]: p.drawLine(line) self.pen.setColor(Qt.red) p.setPen(self.pen) for line in self.lines[self.num_of_lines_generations_back[1]:]: p.drawLine(line) print("lines:", len(self.lines)) print("ends:", len(self.free_ends)) print("--------") if __name__ == '__main__': anim = Anim() def callback(scale=(1, 64), period=(1, 1000, 1000)): anim.scale = 1 / scale anim.anim_period = period if anim.timer.isActive(): anim.timer.stop() anim.timer.start(anim.anim_period) anim.update() qt_app(manipulate(anim, callback))
return self.head - self.tail def get(self, xtranslate=0, ytranslate=0): if not self.points: self.points = self._recalculate_points() polygon = QPolygonF(self.points) polygon.translate(xtranslate, ytranslate) return polygon if __name__ == "__main__": from custom_utils.qt import Canvas, qt_app from PyQt5.QtCore import Qt c = Canvas() def redraw(): c.p.setPen(Qt.NoPen) c.p.setBrush(Qt.black) c.p.translate(250, 250) arr = Arrow(-50, 50, rel_arrowhead_length=0.5) c.p.drawPolygon(arr.get()) c.redraw = redraw qt_app(c)
self.width() / 2, self.height() - 100, 100, 100): p.setPen(Qt.NoPen) p.setBrush(Qt.green) with translate(p, m.lend_pos, 0): p.drawEllipse(self.hinge_box.get()) with translate(p, m.rend_pos, 0): p.drawEllipse(self.hinge_box.get()) p.setBrush(Qt.blue) with translate(p, *m.l_M_pos.get()): p.drawRect(self.l_mass.get()) p.setBrush(Qt.red) with translate(p, *m.r_M_pos.get()): p.drawRect(self.r_mass.get()) pen = QPen(Qt.black) pen.setWidthF(0.02) p.setPen(pen) p.drawLine(QLineF(m.lend_pos, 0, *m.l_M_pos.get())) p.drawLine(QLineF(m.rend_pos, 0, *m.r_M_pos.get())) p.drawLine(QLineF(*m.l_M_pos.get(), *m.r_M_pos.get())) if __name__ == "__main__": model = Model() qt_app(Anim(model))
from custom_utils.qt import MayaviWidget, qt_app import numpy as np from numpy import abs class Anim(MayaviWidget): def __init__(self): super().__init__(width=1500, height=900) x, y = np.mgrid[-5:5:200j, -5:5:200j] self.surf = self.mlab.surf(x, y, self.func(x, y, 0)) self.timeout(0) def timeout(self, frame): x = self.surf.mlab_source.x y = self.surf.mlab_source.y self.surf.mlab_source.scalars = self.func(x, y, frame) def func(self, x, y, i): return np.sin((np.sin(i / 10) + 2) * 0.2 * (x**2 + y**2)) anim = Anim() anim.start_timer(10) qt_app(anim)
from custom_utils.science.imports import * from custom_utils.qt import MatplotlibWidget, qt_app class MyMW(MatplotlibWidget): def __init__(self): super().__init__(toolbar=True) self.x = sp.linspace(-10, 10, 200) self.l, = self.ax.plot(self.x, sp.cos(self.x), "k.", ms=2) self.timeout(0) def timeout(self, frame): self.l.set_ydata(sp.cos(self.x + 0.1 * frame)) print(frame) self.fig.canvas.draw() mw = MyMW() mw.start_timer(1) qt_app(mw)
super().__init__() left_supp = plt.Arrow(0, -SUPP_LENGTH, 0, SUPP_LENGTH, fc="black") right_supp = plt.Arrow(model.supp_dist, -SUPP_LENGTH, 0, SUPP_LENGTH, fc="black") self.ax.add_patch(left_supp) self.ax.add_patch(right_supp) self.beam = plt.Rectangle((-1, 0), model.beam_len, BEAM_HEIGHT, fc="black") self.ax.add_patch(self.beam) self.box = plt.Rectangle((-BOX_SIDE / 2, BEAM_HEIGHT), BOX_SIDE, BOX_SIDE, fc="green") self.ax.add_patch(self.box) self.ax.axis("equal") self.ax.autoscale_view() self.fig.tight_layout() qt_app(Animation())
from custom_utils.qt import qt_app, ManipulateWidget, MatplotlibWidget from PyQt5.QtWidgets import QWidget, QVBoxLayout import matplotlib.pyplot as plt import numpy as np class App(QWidget): def __init__(self): super().__init__() self.layout = QVBoxLayout(self) self.setLayout(self.layout) self.mpl = MatplotlibWidget(self) manipulate = ManipulateWidget(self.callback) self.layout.addWidget(self.mpl) self.layout.addWidget(manipulate) x = np.linspace(0, 2 * np.pi, 300) self.line, = self.mpl.ax.plot(x, np.sin(x)) manipulate.call() def callback(self, freq=(1, 10, 3.6657), amp=(0.5, 5, 1)): self.line.set_ydata(amp * np.sin(freq * self.line.get_xdata())) self.mpl.fig.canvas.draw() if __name__ == '__main__': app = App() qt_app(app)
def main(): model = Model() qt_app(Anim(model))
def main(): a = Anim() a.start_timer(0) qt_app(a)
from custom_utils.qt import Canvas, qt_app from custom_utils.qt.graphics import * from ground import Ground class AntPathsAnimation(Canvas): ROWS = 1000 // 4 COLS = 1500 // 4 SIDE = 4 def __init__(self): super().__init__(width=self.COLS * self.SIDE, height=self.ROWS * self.SIDE, antialiasing=False) self.ground = Ground(self.ROWS, self.COLS) def redraw(self): p = self.p with sensible_coordinates(p): for ant in self.ground.ants.values(): ant.move() p.drawRect(*(ant.pos * 4).get(), 4, 4) if __name__ == '__main__': qt_app(AntPathsAnimation())