@window.event def on_draw(dt): window.clear() paths.draw() @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() transform = PanZoom(OrthographicProjection(Position()), aspect=None) n = 2 S = star(n=7) P = np.tile(S.ravel(), n).reshape(n, len(S), 3) P *= np.random.uniform(5, 10, n)[:, np.newaxis, np.newaxis] P[:, :, :2] += np.random.uniform(0, 800, (n, 2))[:, np.newaxis, :] P = P.reshape(n * len(S), 3) print P print len(P) paths = PathCollection(mode="agg", transform=transform) paths.append(P, closed=True, itemsize=len(S)) paths["linewidth"] = 1.0 window.attach(paths["transform"]) window.attach(paths["viewport"]) app.run()
@window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: reset() def reset(): transform.theta = 0 transform.phi = 0 transform.zoom = 16.5 transform = Trackball(Position()) viewport = Viewport() labels = GlyphCollection(transform=transform, viewport=viewport) paths = PathCollection(mode="agg+", transform=transform, viewport=viewport) ticks = SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth="local", color="local") # xmin,xmax = 0,800 # ymin,ymax = 0,800 xmin, xmax = -1, 1 ymin, ymax = -1, 1 z = 0 regular = FontManager.get("OpenSans-Regular.ttf") bold = FontManager.get("OpenSans-Bold.ttf") n = 11 scale = 0.001
@window.event def on_init(): gl.glEnable(gl.GL_DEPTH_TEST) @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() transform = PanZoom(OrthographicProjection(Position(), yinvert=True), aspect=None) paths = PathCollection("agg+", transform=transform, linewidth='shared', color="shared") polygons = PolygonCollection("agg", transform=transform) z = 0 for path in tiger.paths: for vertices, closed in path.vertices: if len(vertices) < 3: continue if path.style.stroke is not None: vertices[:, 2] = z + 0.5 if path.style.stroke_width: stroke_width = path.style.stroke_width.value else: stroke_width = 2.0 paths.append(vertices,
triangles.draw() paths.draw() @window.event def on_init(): gl.glEnable(gl.GL_DEPTH_TEST) @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() transform = PanZoom(OrthographicProjection(Position())) triangles = TriangleCollection("agg", transform=transform, color='shared') paths = PathCollection("agg", transform=transform, color='shared') paths["linewidth"] = 10 P = star() I = triangulate(P) n = 64 for i in range(n): c = i/float(n) d = i x,y = np.random.uniform(0,800,2) s = 25 triangles.append(P*s+(x,y,d), I, color=(0,0,0,.5)) paths.append(P*s+(x,y,(d-1)), closed=True, color=(0,0,0,1)) window.attach(paths["transform"])
return {"type": obj["type"], "coordinates": convert_coordinates(obj["arcs"], topology_arcs, scale, translate)} window = app.Window(2 * 960, 2 * 600, color=(1, 1, 1, 1)) @window.event def on_draw(dt): window.clear() polys.draw() paths.draw() Albers = ConicEqualArea(scale=2 * 1285, parallels=(29.5, 45.5), rotate=(96, 0), translate=(0, 0), center=(0.38, -0.41)) transform = PanZoom(OrthographicProjection(Albers(Position()), aspect=1)) paths = PathCollection("agg+", transform=transform, linewidth="shared", color="shared") polys = PolygonCollection("raw", transform=transform, color="shared") with open(data.get("us.json"), "r") as file: topology = json.load(file) scale = topology["transform"]["scale"] translate = topology["transform"]["translate"] arcs = topology["arcs"] linewidth = 2.5 color = 0.0, 0.0, 0.0, 1.0 land = topology["objects"]["land"] for coords in geometry(land, arcs, scale, translate)["coordinates"]: for path in coords: V = np.zeros((len(path), 3))
@window.event def on_draw(dt): window.clear() paths.draw() @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() transform = PanZoom(OrthographicProjection(Position()), aspect=None) n = 2500 S = star(n=5) P = np.tile(S.ravel(), n).reshape(n, len(S), 3) P *= np.random.uniform(5, 10, n)[:, np.newaxis, np.newaxis] P[:, :, :2] += np.random.uniform(0, 800, (n, 2))[:, np.newaxis, :] P = P.reshape(n * len(S), 3) paths = PathCollection(mode="agg", transform=transform) paths.append(P, closed=True, itemsize=len(S)) paths["linewidth"] = 1.0 window.attach(paths["transform"]) window.attach(paths["viewport"]) app.run()
@window.event def on_draw(dt): window.clear() polys.draw() paths.draw() Albers = ConicEqualArea(scale=2 * 1285, parallels=(29.5, 45.5), rotate=(96, 0), translate=(0, 0), center=(0.38, -0.41)) transform = PanZoom(OrthographicProjection(Albers(Position()), aspect=1)) paths = PathCollection("agg+", transform=transform, linewidth='shared', color="shared") polys = PolygonCollection("raw", transform=transform, color="shared") with open(data.get("us.json"), 'r') as file: topology = json.load(file) scale = topology['transform']['scale'] translate = topology['transform']['translate'] arcs = topology["arcs"] linewidth = 2.5 color = 0.0, 0.0, 0.0, 1.0 land = topology["objects"]["land"] for coords in geometry(land, arcs, scale, translate)["coordinates"]: for path in coords:
gl_FragColor = mix(white,blue,v); } """ transform = Arcball(Position(),znear=1,zfar=10) viewport = Viewport() radius = 1.5 vertices, indices = sphere(radius, 64, 64) earth = gloo.Program(vertex, fragment) earth.bind(vertices) earth['texture'] = data.get("earth-black.jpg") earth['texture'].interpolation = gl.GL_LINEAR earth['transform'] = transform paths = PathCollection(mode="agg+", color="global", linewidth="global", viewport=viewport, transform=transform) paths["color"] = 0,0,0,0.5 paths["linewidth"] = 1.0 theta = np.linspace(0, 2*np.pi, 64, endpoint=True) for phi in np.linspace(0, np.pi, 12, endpoint=False): paths.append(spheric_to_cartesian(phi, theta, radius*1.01), closed=True) phi = np.linspace(0, 2*np.pi, 64, endpoint=True) for theta in np.linspace(0, np.pi, 19, endpoint=True)[1:-1]: paths.append(spheric_to_cartesian(phi, theta, radius*1.01), closed=True) vertex = """ #include "math/constants.glsl"
gl.glDepthMask(gl.GL_FALSE) outlines.draw() gl.glDepthMask(gl.GL_TRUE) @window.event def on_init(): gl.glEnable(gl.GL_DEPTH_TEST) gl.glPolygonOffset(1, 1) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glLineWidth(0.75) transform = Trackball(Position()) cells = TriangleCollection("raw", transform=transform, color="shared") outlines = PathCollection("raw", transform=transform, color="shared") # Random points n = 2000 points = np.random.normal(size=(n, 3)) points /= np.linalg.norm(points, axis=1)[:, np.newaxis] # Voronoi cells sv = SphericalVoronoi(points, 2, (0, 0, 0)) sv.sort_vertices_of_regions() for region in sv.regions: z = np.random.uniform(0, 1) V = (1.0 + 0.1 * z) * sv.vertices[region] color = (0.75 + 0.25 * z, 0.25 + 0.75 * z, 0.25 + 0.75 * z, 1)
@window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: reset() def reset(): transform.theta = 0 transform.phi = 0 transform.zoom = 16.5 transform = Trackball(Position()) viewport = Viewport() labels = GlyphCollection(transform=transform, viewport=viewport) paths = PathCollection(mode="agg+", transform=transform, viewport=viewport) ticks = SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth='local', color='local') # xmin,xmax = 0,800 # ymin,ymax = 0,800 xmin, xmax = -1, 1 ymin, ymax = -1, 1 z = 0 regular = FontManager.get("OpenSans-Regular.ttf") bold = FontManager.get("OpenSans-Bold.ttf")
gl.glDepthMask(gl.GL_FALSE) outlines.draw() gl.glDepthMask(gl.GL_TRUE) @window.event def on_init(): gl.glEnable(gl.GL_DEPTH_TEST) gl.glPolygonOffset(1, 1) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glLineWidth(0.75) transform = Trackball(Position()) cells = TriangleCollection("raw", transform=transform, color='shared') outlines = PathCollection("raw", transform=transform, color='shared') # Random points n = 2000 points = np.random.normal(size=(n, 3)) points /= np.linalg.norm(points, axis=1)[:, np.newaxis] # Voronoi cells sv = SphericalVoronoi(points, 2, (0, 0, 0)) sv.sort_vertices_of_regions() for region in sv.regions: z = np.random.uniform(0, 1) V = (1.0 + 0.1 * z) * sv.vertices[region] color = (.75 + .25 * z, .25 + .75 * z, .25 + .75 * z, 1)
@window.event def on_mouse_release(x, y, button): global P if len(paths) > 0: del paths[0] if len(polys) > 0: del polys[0] if len(P): paths.append(np.array(P), closed=True) polys.append(np.array(P)) @window.event def on_mouse_drag(x, y, dx, dy, button): global P P.append((x, window.height - y, 0)) if len(paths) > 0: del paths[0] paths.append(np.array(P), closed=False) transform = OrthographicProjection(Position()) paths = PathCollection(mode="agg", transform=transform) polys = PolygonCollection(mode="agg", transform=transform, color="global") paths["linewidth"] = 1.0 paths["color"] = 0.0, 0.0, 0.0, 1.00 polys["color"] = 0.0, 0.0, 0.0, 0.10 window.attach(paths["transform"]) window.attach(paths["viewport"]) app.run()
paths.draw() @window.event def on_init(): gl.glEnable(gl.GL_DEPTH_TEST) @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() transform = PanZoom(OrthographicProjection(Position(), yinvert=True), aspect=None) paths = PathCollection("agg+", transform=transform, linewidth="shared", color="shared") polygons = PolygonCollection("agg", transform=transform) z = 0 for path in tiger.paths: for vertices, closed in path.vertices: if len(vertices) < 3: continue if path.style.stroke is not None: vertices[:, 2] = z + 0.5 if path.style.stroke_width: stroke_width = path.style.stroke_width.value else: stroke_width = 2.0 paths.append(vertices, closed=closed, color=path.style.stroke.rgba, linewidth=stroke_width) if path.style.fill is not None:
def start_visualizing(cluster_points, frame_to_show): window = app.Window(DIM, DIM, color=(BLACK if BLACK_ON_WHITE else (1, 2, 1, 1))) point_collection = PointCollection("agg", color="local", size="local") paths = PathCollection(mode="agg") @window.event def on_draw(dt): global FRAME_N window.clear() point_collection.draw() if not cluster_points.empty(): possible = cluster_points.get() print "frame", FRAME_N FRAME_N += 1 if frame_to_show > -1 and not (FRAME_N - 1) == frame_to_show: while not possible == TERMINATOR: possible = cluster_points.get() return time.sleep(DRAW_DELAY) while len(point_collection) > 0: del point_collection[0] while len(paths) > 0: del paths[0] while not possible == TERMINATOR: if FILE == possible[0]: print possible[1] possible = cluster_points.get() continue if ALL_DONE == possible: print "Quitting" app.quit() sys.exit() break if len(possible) == 4: type, data, color, size = possible if POINT == type: new_point = [[0.7 * x for x in data]] new_point[0][1] *= -1 point_collection.append(new_point, color=color, size=size) elif LINE == type: path = [] for hop in data: new_hop = [round(0.7 * abs(x), 5) for x in hop] path.append(new_hop) path = np.asarray(path) print path, len(path) paths.append(path, closed=True, itemsize=len(path)) paths["linewidth"] = 3.0 possible = cluster_points.get() window.attach(point_collection["transform"]) window.attach(point_collection["viewport"]) app.run()