Пример #1
0
    def __init__(self,
                 x,
                 transform=None,
                 window=None,
                 linewidth=2,
                 color=(0, 0, 0),
                 scale=1.0,
                 origin=(0, 0),
                 **kwargs):

        self.scale = scale
        self.origin = origin

        if transform is None:
            transform = OrthographicProjection(Position(), normalize=True)

        MarkerCollection.__init__(self, marker='disc', transform=transform)
        self.append(x,
                    size=15,
                    linewidth=linewidth,
                    itemsize=1,
                    fg_color=Color(color).rgba,
                    bg_color=(1, .5, .5, 1))
        # self['antialias'] = 1

        if window is not None:
            window.attach(self['transform'])
            window.attach(self['viewport'])
Пример #2
0
    def make_programs(self, window):

        transform = OrthographicProjection(Position(), aspect=None, normalize=True)

        x = self.model.positions(z=True).T
        self.shapes = {
            'links': Lines(x[:, 0], x[:, 1], window=window, transform=transform, linewidth=20.0, color=(0.75, 0.75, 0.75)),
            'joints': Markers(x, window=window, size=15, linewidth=2, color=(0, 0, 0))
        }
Пример #3
0
    def __init__(self,
                 *args,
                 transform=None,
                 window=None,
                 linewidth=10,
                 n=101,
                 color=(0, 0, 0),
                 scale=1.0,
                 origin=(0, 0),
                 **kwargs):

        self.scale = scale
        self.origin = origin

        if len(args) == 1:
            self.x, self.y = np.linspace(-1, 1, len(args[0])), args[0]
        elif len(args) == 2:
            self.x, self.y = args
            n = len(args[0])
        else:
            self.x, self.y = np.linspace(-1, 1, n), np.zeros(n)
            # self.x, self.y = np.linspace(-1, 1, n - 1), np.zeros(n - 1)

        if transform is None:
            transform = OrthographicProjection(Position(), normalize=True)

        AggSegmentCollection.__init__(self,
                                      linewidth='local',
                                      transform=transform)
        self.append(self.P0,
                    self.P1,
                    linewidth=linewidth,
                    color=np.tile(Color(color).rgba, (n + 1, 1)))
        self['antialias'] = 1

        if window is not None:
            window.attach(self['transform'])
            window.attach(self['viewport'])
for j in range(3):
    for i in range(8):
        x = (i+0.5)*radius
        y = (j+0.5)*radius
        index = j*8+i
        data['orientation'][index] = 0
        data['position'][index]    = x, y, 0
        data['size'][index]        = .75*radius
        data['linewidth'][index]   = 1+i*2
        data['antialias'][index] = 1
        if j == 2:
            data['antialias'][index] = 1+i*3
        elif j == 1:
            v = 0.35 + 0.5 * (i/8.0)
            data['fg_color'][index] = 0,0,0,1
            data['bg_color'][index] = 1,1,.85,1
        elif j == 0:
            v = i / 8.0
            data['fg_color'][index] = 0,0,0,1
            data['bg_color'][index] = 0,0,0,1

program = gloo.Program(vertex, "markers/marker.frag")
program.bind(data)
program['marker'] = "clover"
program['paint']  = "outline"
transform = OrthographicProjection(Position("position"))
program['transform'] = transform
window.attach(transform)

app.run()
Пример #5
0
    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"])
Пример #6
0
    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:
Пример #7
0
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
from glumpy import app
from glumpy.log import log
from glumpy.graphics.text import FontManager
from glumpy.graphics.collections import GlyphCollection
from glumpy.transforms import Position, OrthographicProjection, Viewport

window = app.Window(width=1200, height=800, color=(1, 1, 1, 1))


@window.event
def on_draw(dt):
    window.clear()
    labels.draw()


labels = GlyphCollection('agg', transform=OrthographicProjection(Position()))
text = "The quick brown fox jumps over the lazy dog"
x, y, z = 2, window.height, 0

log.info("Caching texture fonts")
for i in range(6, 54, 2):
    font = FontManager.get("OpenSans-Regular.ttf", size=i, mode='agg')
    y -= i * 1.1
    labels.append(text, font, origin=(x, y, z), anchor_x="left")

window.attach(labels["transform"])
window.attach(labels["viewport"])
app.run()
Пример #8
0
    def make_programs(self, window):

        transform = OrthographicProjection(Position(),
                                           aspect=None,
                                           normalize=True)

        x = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])
        self.shapes = {
            'reflexive':
            Lines(n=self.model.neurons,
                  color=Color('baby blue').rgb,
                  linewidth=10,
                  transform=transform,
                  window=window),
            'reflective':
            Lines(n=self.model.neurons,
                  color=Color('light purple').rgb,
                  linewidth=10,
                  transform=transform,
                  window=window),
            'stimulus':
            Lines(n=self.model.neurons,
                  color=Color('red').rgb,
                  linewidth=5,
                  transform=transform,
                  window=window),
            'inhibition':
            Lines(n=self.model.neurons,
                  color=Color('dark blue').rgb,
                  linewidth=5,
                  transform=transform,
                  window=window),
            'bias':
            Lines(n=self.model.neurons,
                  color=Color('soft pink').rgb,
                  linewidth=5,
                  transform=transform,
                  window=window),
            'reflexive_out':
            Lines(n=self.model.neurons,
                  color=Color('ocean blue').rgb,
                  linewidth=10,
                  transform=transform,
                  window=window),
            'reflective_out':
            Lines(n=self.model.neurons,
                  color=Color('violet').rgb,
                  linewidth=10,
                  transform=transform,
                  window=window),
            'attention':
            Markers(x,
                    window=window,
                    size=15,
                    linewidth=2,
                    color=(1, 1, 1),
                    bg_color=(0, 0, 0)),
            'intention':
            Markers(x,
                    window=window,
                    size=15,
                    linewidth=2,
                    color=(1, 1, 1),
                    bg_color=(0, 0, 0))
        }
Пример #9
0
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
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))
Пример #11
0
                          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
Пример #12
0
    source=parents.pop(0)
    for i in range(branch):
        try:
            target=next(nodes)
            parents.append(target)
            A[source,target] = 1
        except StopIteration:
            break

# Current selected node
selected = -1

# Get edges
src,tgt = np.nonzero(A)

transform = OrthographicProjection(Position(), aspect=None)
viewport = Viewport()


markers = collections.MarkerCollection(marker='disc', transform=transform, viewport=viewport)
markers.append(N, size=15, linewidth=2, itemsize=1,
               fg_color=(1,1,1,1), bg_color=(1,.5,.5,1))
segments = collections.SegmentCollection('agg', transform=transform, viewport=viewport)
segments.append(N[src], N[tgt], linewidth=1.0, itemsize=1,
                color=(0.75,0.75,0.75,1.00))

window.attach(transform)
window.attach(viewport)

app.run()
Пример #13
0
{
    gl_Position = <transform>;
}
"""

fragment = """
void main()
{
    gl_FragColor = vec4(1,0,0,1);
}
"""

window = app.Window(width=800, height=800)


@window.event
def on_draw(dt):
    window.clear()
    quad.draw(gl.GL_TRIANGLE_STRIP)


@window.event
def on_resize(w, h):
    quad['position'] = [(w - 100, h - 100), (w - 100, h), (w, h - 100), (w, h)]


quad = gloo.Program(vertex, fragment, count=4)
quad["transform"] = OrthographicProjection(Position("position"))
window.attach(quad["transform"])
app.run()