예제 #1
0
def disp_circuit(by_id, *map_to_col_list):
  canvas = vapp.Canvas(size=(800, 800), keys='interactive', title='Floating Pwn2Win Mask')
  gloo.set_viewport(0, 0, 800, 800)
  gloo.set_viewport(0, 0, canvas.size[0], canvas.size[1])
  gloo.set_state("translucent", depth_test=False)

  panzoom = PanZoomTransform(canvas, aspect=1)
  polys = PolygonCollection("agg", color="local", transform=panzoom)
  shift = np.zeros((1, 2))

  for colmap in map_to_col_list:
    nshift = np.zeros((1, 2))
    minp = np.zeros((1, 2))
    for entry in by_id.values():
      if entry.box.empty(): continue
      if entry.nodisplay: continue
      key = entry.idx
      if not key in colmap: continue

      points = np.concatenate((entry.box.poly() / 1e5 + shift, np.zeros((4, 1))), axis=1)
      nshift = np.maximum(nshift, np.amax(points, axis=0)[:2])
      minp = np.minimum(minp, np.amin(points, axis=0)[:2])
      polys.append(points, color=colmap[key].rgba)
    shift = (nshift - minp) * 1.1
    shift[0, 1] = 0
  polys.update.connect(canvas.update)

  @canvas.connect
  def on_draw(e):
    gloo.clear('white')
    polys.draw()

  @canvas.connect
  def on_resize(event):
    width, height = event.size
    gloo.set_viewport(0, 0, width, height)

  canvas.show()
  vapp.run()
예제 #2
0
from vispy.visuals.transforms import PanZoomTransform

path = load_data_file('tiger/tiger.svg')
tiger = Document(path)

width, height = int(tiger.viewport.width), int(tiger.viewport.height)
canvas = app.Canvas(size=(width, height), show=True, keys='interactive')
gloo.set_viewport(0, 0, width, height)
gloo.set_state("translucent", depth_test=True)

panzoom = PanZoomTransform(canvas, aspect=1.0)
paths = PathCollection("agg+",
                       linewidth='shared',
                       color="shared",
                       transform=panzoom)
polys = PolygonCollection("agg", transform=panzoom)
paths.update.connect(canvas.update)

z = 0
for path in tiger.paths:
    for vertices, closed in path.vertices:

        vertices = 2 * (vertices / (width, height, 1)) - 1
        vertices[:, 1] = -vertices[:, 1]
        if len(vertices) < 3:
            continue
        if path.style.stroke is not None:
            vertices[:, 2] = z - 0.5 / 1000.
            if path.style.stroke_width:
                stroke_width = path.style.stroke_width.value
            else:
예제 #3
0
    p[:, :2] = P
    p = unique_rows(p)
    if len(p) > 1:
        paths.append(p, closed=True)
    if len(p) > 2:
        polys.append(p, color=color)


# Create the canvas.
canvas = app.Canvas(size=(800, 800), keys='interactive')
gloo.set_viewport(0, 0, canvas.size[0], canvas.size[1])
gloo.set_state("translucent", depth_test=False)

panzoom = PanZoomTransform(canvas, aspect=1)
paths = PathCollection(mode="agg+", color="global", transform=panzoom)
polys = PolygonCollection("raw", color="local", transform=panzoom)
paths.update.connect(canvas.update)

for feature in geo["features"]:
    if feature["geometry"]["type"] == 'Polygon':
        path = feature["geometry"]["coordinates"]
        rgba = np.random.uniform(0.5, .8, 4)
        rgba[3] = 1
        add(path[0], color=rgba)

    elif feature["geometry"]["type"] == 'MultiPolygon':
        coordinates = feature["geometry"]["coordinates"]
        for path in coordinates:
            rgba = np.random.uniform(0.5, .8, 4)
            rgba[3] = 1
            add(path[0], color=rgba)
예제 #4
0
canvas = app.Canvas(size=(800, 800), show=True, keys='interactive')
gloo.set_viewport(0, 0, canvas.size[0], canvas.size[1])
gloo.set_state("translucent", depth_test=False)


def star(inner=0.5, outer=1.0, n=5):
    R = np.array([inner, outer] * n)
    T = np.linspace(0, 2 * np.pi, 2 * n, endpoint=False)
    P = np.zeros((2 * n, 3))
    P[:, 0] = R * np.cos(T)
    P[:, 1] = R * np.sin(T)
    return P

paths = PathCollection("agg", color='shared')
polys = PolygonCollection("raw", color='shared')

P = star()

n = 100
for i in range(n):
    c = i / float(n)
    x, y = np.random.uniform(-1, +1, 2)
    s = 100 / 800.0
    polys.append(P * s + (x, y, i / 1000.), color=(1, 0, 0, .5))
    paths.append(
        P * s + (x, y, (i - 1) / 1000.), closed=True, color=(0, 0, 0, .5))

paths["linewidth"] = 1.0
paths['viewport'] = 0, 0, 800, 800
예제 #5
0
파일: tiger.py 프로젝트: Calvarez20/vispy
from vispy.util.svg import Document
from vispy.visuals.collections import PathCollection, PolygonCollection
from vispy.visuals.transforms import PanZoomTransform

path = load_data_file('tiger/tiger.svg')
tiger = Document(path)

width, height = int(tiger.viewport.width), int(tiger.viewport.height)
canvas = app.Canvas(size=(width, height), show=True, keys='interactive')
gloo.set_viewport(0, 0, width, height)
gloo.set_state("translucent", depth_test=True)

panzoom = PanZoomTransform(canvas, aspect=1.0)
paths = PathCollection(
    "agg+", linewidth='shared', color="shared", transform=panzoom)
polys = PolygonCollection("agg", transform=panzoom)
paths.update.connect(canvas.update)

z = 0
for path in tiger.paths:
    for vertices, closed in path.vertices:

        vertices = 2 * (vertices / (width, height, 1)) - 1
        vertices[:, 1] = -vertices[:, 1]
        if len(vertices) < 3:
            continue
        if path.style.stroke is not None:
            vertices[:, 2] = z - 0.5 / 1000.
            if path.style.stroke_width:
                stroke_width = path.style.stroke_width.value
            else: