@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()
# Setting initial values P[0] = 0.0, 1.0, 1.05 # Stepping through "time" dt = 100.0 / n for i in range(n): # Derivatives of the X, Y, Z state P[i + 1] = P[i] + iterate(P[i], dt=dt) # Normalize vmin, vmax = P.min(), P.max() P = 2 * (P - vmin) / (vmax - vmin) - 1 # Centering P[:, 0] -= (P[:, 0].max() + P[:, 0].min()) / 2.0 P[:, 1] -= (P[:, 1].max() + P[:, 1].min()) / 2.0 P[:, 2] -= (P[:, 2].max() + P[:, 2].min()) / 2.0 return P paths.append(lorenz(), color=(0, 0, 1, 1), closed=False) paths["color"] = 0, 0, 1, 1 reset() window.attach(paths["transform"]) window.attach(paths["viewport"]) app.run()
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: if path.style.stroke is None: vertices[:, 2] = z + 0.25 paths.append(vertices, closed=closed, color=path.style.fill.rgba, linewidth=1) vertices[:, 2] = z polygons.append(vertices, color=path.style.fill.rgba) z += 1 window.attach(paths["transform"]) window.attach(paths["viewport"])
@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"]) window.attach(paths["viewport"]) app.run()
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)) V[:, :2] = np.array(path) paths.append(V, closed=True, color=color, linewidth=linewidth) linewidth = 1.0 color = 0.0, 0.0, 0.0, 1.0 for state in topology["objects"]["states"]["geometries"]: if state["type"] == "Polygon": P = geometry(state, arcs, scale, translate)["coordinates"][0] V = np.zeros((len(P), 3)) V[:, :2] = P paths.append(V, closed=True, color=color, linewidth=linewidth) elif state["type"] == "MultiPolygon": for P in geometry(state, arcs, scale, translate)["coordinates"]: V = np.zeros((len(P[0]), 3)) V[:, :2] = P[0] paths.append(V, closed=True, color=color, linewidth=linewidth)
@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()
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)) V[:, :2] = np.array(path) paths.append(V, closed=True, color=color, linewidth=linewidth) linewidth = 1.0 color = 0.0, 0.0, 0.0, 1.0 for state in topology["objects"]["states"]["geometries"]: if state["type"] == "Polygon": P = geometry(state, arcs, scale, translate)["coordinates"][0] V = np.zeros((len(P), 3)) V[:, :2] = P paths.append(V, closed=True, color=color, linewidth=linewidth) elif state["type"] == "MultiPolygon": for P in geometry(state, arcs, scale, translate)["coordinates"]: V = np.zeros((len(P[0]), 3)) V[:, :2] = P[0] paths.append(V, closed=True, color=color, linewidth=linewidth)
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" varying float v_size; varying vec4 v_fg_color; varying vec4 v_bg_color; varying vec2 v_orientation; varying float v_antialias;
P = np.empty((n + 1, 3)) # Setting initial values P[0] = 0., 1., 1.05 # Stepping through "time" dt = 100.0 / n for i in range(n): # Derivatives of the X, Y, Z state P[i + 1] = P[i] + iterate(P[i], dt=dt) # Normalize vmin, vmax = P.min(), P.max() P = 2 * (P - vmin) / (vmax - vmin) - 1 # Centering P[:, 0] -= (P[:, 0].max() + P[:, 0].min()) / 2.0 P[:, 1] -= (P[:, 1].max() + P[:, 1].min()) / 2.0 P[:, 2] -= (P[:, 2].max() + P[:, 2].min()) / 2.0 return P paths.append(lorenz(), color=(0, 0, 1, 1), closed=False) paths["color"] = 0, 0, 1, 1 reset() window.attach(paths["transform"]) window.attach(paths["viewport"]) app.run()
# 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) I = np.zeros((len(V) - 2, 3)) I[:, 1] = 1 + np.arange(len(I)) I[:, 2] = 1 + I[:, 1] cells.append(V, I.ravel(), color=color) outlines.append(V, color=(0, 0, 0, 1), closed=True) V_ = [] for v1, v2 in zip(V[:-1], V[1:]): V_.extend(((0, 0, 0), v1, v2)) V_.extend(((0, 0, 0), V[-1], V[0])) V_ = np.array(V_) I = np.arange(len(V_)) cells.append(V_, I, color=color) outlines.append(V_, color=(0, 0, 0, 1), closed=True) window.attach(outlines["transform"]) window.attach(outlines["viewport"]) app.run()
# 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) I = np.zeros((len(V) - 2, 3)) I[:, 1] = 1 + np.arange(len(I)) I[:, 2] = 1 + I[:, 1] cells.append(V, I.ravel(), color=color) outlines.append(V, color=(0, 0, 0, 1), closed=True) V_ = [] for v1, v2 in zip(V[:-1], V[1:]): V_.extend(((0, 0, 0), v1, v2)) V_.extend(((0, 0, 0), V[-1], V[0])) V_ = np.array(V_) I = np.arange(len(V_)) cells.append(V_, I, color=color) outlines.append(V_, color=(0, 0, 0, 1), closed=True) window.attach(outlines["transform"]) window.attach(outlines["viewport"]) app.run()
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: if path.style.stroke is None: vertices[:, 2] = z + 0.25 paths.append(vertices, closed=closed, color=path.style.fill.rgba, linewidth=1) vertices[:, 2] = z polygons.append(vertices, color=path.style.fill.rgba) z += 1 window.attach(paths["transform"]) window.attach(paths["viewport"]) app.run()