polygons.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(), 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
return P @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"])
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
@window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() def func3(x, y): return (1 - x / 2 + x**5 + y**3) * np.exp(-x**2 - y**2) x = np.linspace(-2.0, 2.0, 256).astype(np.float32) y = np.linspace(-2.0, 2.0, 256).astype(np.float32) X, Y = np.meshgrid(x, y) Z = func3(X, Y) program = gloo.Program(vertex, fragment) V, I = primitives.plane(2.0, n=64) program.bind(V) program['data'] = (Z - Z.min()) / (Z.max() - Z.min()) program['data'].interpolation = gl.GL_NEAREST program['data_shape'] = Z.shape[1], Z.shape[0] program['u_kernel'] = data.get("spatial-filters.npy") program['u_kernel'].interpolation = gl.GL_LINEAR transform = PanZoom(aspect=1) program['transform'] = transform window.attach(transform) app.run()
origin = (x,y,0), scale = 0.002, direction = (1,0,0), anchor_x = "left", anchor_y = "center") if header is not None: labels.append(header, regular, color=c, origin = (x,ymax - 0.25*(ymax-ymin),0), scale = 0.005, direction = (1,0,0), anchor_x = "left", anchor_y = "center") x = xmax - 0.05*(xmax-xmin) labels.append(values[i].upper(), regular, color=c, origin = (x,y,0), scale = 0.002, direction = (1,0,0), anchor_x = "right", anchor_y = "center") transform = PanZoom(OrthographicProjection(Position(),normalize=True),aspect=1) transform.zoom = 0.165 viewport = Viewport() quads = collections.TriangleCollection(transform = transform, viewport=viewport) labels = collections.GlyphCollection(transform = transform, viewport=viewport) regular = FontManager.get("OpenSans-Regular.ttf") x,y = -2.5*2.6,+4 for i,name in enumerate(["Red", "Pink", "Purple", "Deep Purple", "Indigo", "Blue", "Light Blue", "Cyan", "Teal", "Green", "Light Green", "Lime", "Yellow", "Amber", "Orange", "Deep Orange", "Brown", "Grey"]): family = "material:%s" % name if i > 0 and (i % 6) == 0: y -= 4
if ( i < n ) { float nu = log(log(sqrt(d))/log_2)/log_2; float index = float(i) + 1.0 - nu; float v = pow(index/float(n),0.5); gl_FragColor = vec4(hot(v),1.0); } else { gl_FragColor = vec4(hot(0.0),1.0); } } """ window = app.Window(width=1024, height=1024) @window.event def on_draw(dt): window.clear() program.draw(gl.GL_TRIANGLE_STRIP) @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() program = gloo.Program(vertex, fragment, count=4) program['position'] = [(-1,-1), (-1, 1), ( 1,-1), ( 1, 1)] program['texcoord'] = [( 0, 1), ( 0, 0), ( 1, 1), ( 1, 0)] transform = PanZoom(Position("position"),aspect=1) program['transform'] = transform window.attach(transform) app.run()
def on_draw(dt): window.clear() 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))
direction=(1, 0, 0), anchor_x="left", anchor_y="center") x = xmax - 0.05 * (xmax - xmin) labels.append(values[i].upper(), regular, color=c, origin=(x, y, 0), scale=0.002, direction=(1, 0, 0), anchor_x="right", anchor_y="center") transform = PanZoom(OrthographicProjection(Position(), normalize=True), aspect=1) transform.zoom = 0.165 viewport = Viewport() quads = collections.TriangleCollection(transform=transform, viewport=viewport) labels = collections.GlyphCollection(transform=transform, viewport=viewport) regular = FontManager.get("OpenSans-Regular.ttf") x, y = -2.5 * 2.6, +4 for i, name in enumerate([ "Red", "Pink", "Purple", "Deep Purple", "Indigo", "Blue", "Light Blue", "Cyan", "Teal", "Green", "Light Green", "Lime", "Yellow", "Amber", "Orange", "Deep Orange", "Brown", "Grey" ]): family = "material:%s" % name if i > 0 and (i % 6) == 0:
gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) color_all_cubes() # Outlined cube # gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) # gl.glEnable(gl.GL_BLEND) # gl.glDepthMask(gl.GL_FALSE) # cube['u_color'] = 0, 0, 0, 1 # cube.draw(gl.GL_LINES, outline) # cube2['u_color'] = 0, 0, 0, 1 # cube2.draw(gl.GL_LINES, outline) # gl.glDepthMask(gl.GL_TRUE) zoom = PanZoom(Position("position"), aspect=1, zoom=1) @window.event def on_key_press(key, modifiers): global phi, theta if key == app.window.key.UP: for cube in CUBES: glm.translate(view, 0, -0.01, 0) cube['view'] = view if key == app.window.key.DOWN: for cube in CUBES: glm.translate(view, 0, 0.01, 0) cube['view'] = view if key == app.window.key.LEFT: for cube in CUBES: