Created
March 31, 2019 19:42
-
-
Save GuillaumeFavelier/4e6df0cddb7c006318ac3a5d99cf8574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import numpy as np | |
from vispy import app, gloo, visuals | |
from vispy.visuals import transforms | |
N = 100 | |
n = 10 | |
width = 800 | |
height = 600 | |
positions = np.random.rand(N, 3) | |
positions[:, 0] *= width | |
positions[:, 1] *= height | |
positions[:, 2] = 0 | |
positions = np.floor(positions) | |
class Canvas(app.Canvas): | |
def __init__(self): | |
app.Canvas.__init__(self, keys='interactive', size=(800, 800)) | |
global pos | |
self.visuals = [] | |
for p in positions: | |
rect = visuals.RectangleVisual(center=p, height=n, | |
width=n, | |
color='white') | |
rect.transform = transforms.NullTransform() | |
self.visuals.append(rect) | |
self.show() | |
def on_resize(self, event): | |
vp = (0, 0, self.physical_size[0], self.physical_size[1]) | |
for visual in self.visuals: | |
visual.transforms.configure(canvas=self, viewport=vp) | |
def on_draw(self, ev): | |
gloo.set_clear_color((0, 0, 0, 1)) | |
gloo.set_viewport(0, 0, *self.physical_size) | |
gloo.clear() | |
for vis in self.visuals: | |
vis.draw() | |
if __name__ == '__main__': | |
win = Canvas() | |
if sys.flags.interactive != 1: | |
win.app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment