Esempio n. 1
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()
Esempio n. 2
0
for z in np.linspace(zmin, zmax, n_major)[0:-1]:
    paths.append(linepath((xmin, ymin, z), (xmin + length_major, ymin, z)),
                 linewidth=2.0,
                 color=(0, 0, 0, 1))
for z in np.linspace(zmin, zmax, n_minor)[0:-1]:
    paths.append(linepath((xmin, ymin, z), (xmin + length_minor, ymin, z)),
                 linewidth=1.0,
                 color=(0, 0, 0, 1))

# Tick labels
# -------------------------------------
labels = GlyphCollection(transform=transform,
                         viewport=viewport,
                         vertex='collections/tick-labels.vert')

regular = FontManager.get("OpenSans-Regular.ttf")
n = 10 + 1
scale = 0.002
for i, y in enumerate(np.linspace(xmin, xmax, n)[:-1]):
    text = "%.2f" % (i / 10.0)
    labels.append(text,
                  regular,
                  origin=(xmax + 0.1, y, zmin),
                  scale=0.65 * scale,
                  direction=(1, 0, 0),
                  anchor_x="left",
                  anchor_y="center")
    labels.append(text,
                  regular,
                  origin=(y, -.001, zmin),
                  scale=0.65 * scale,
Esempio n. 3
0
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
for i, y in enumerate(np.linspace(xmin, xmax, n)):
    text = "%.2f" % (i / 10.0)
    labels.append(
        text, regular, origin=(1.05, y, z), scale=scale, direction=(1, 0, 0), anchor_x="left", anchor_y="center"
    )
    labels.append(
        text, regular, origin=(y, -1.05, z), scale=scale, direction=(1, 0, 0), anchor_x="center", anchor_y="top"
    )

title = "Lorenz strange attractor"
labels.append(
    title, bold, origin=(0, 1.1, z), scale=2 * scale, direction=(1, 0, 0), anchor_x="center", anchor_y="center"
Esempio n. 4
0
    v_texcoord = texcoord;
    <viewport.transform>;

    float scale = (3.5 - length(gl_Position.xyz)/length(vec3(1.5)));
    v_color.a = scale;

    // We set actual position after transform
    v_offset = 3.0*(offset + origin.x - int(origin.x));
    gl_Position /= gl_Position.w;
    gl_Position = gl_Position + vec4(2.0*position/<viewport.viewport_global>.zw,0,0);
}
"""

labels = GlyphCollection('agg', vertex=vertex,
                         transform=transform, viewport=viewport)
font = FontManager.get("OpenSans-Regular.ttf", size=16, mode='agg')
for i in range(len(P)):
    labels.append(C[i], font, origin = P[i])
labels["position"][:,1] -= 20
    
window = app.Window(width=1024, height=1024, color=(.2,.2,.35,1))
window.attach(transform)
window.attach(viewport)

@window.event
def on_draw(dt):
    window.clear()
    gl.glEnable(gl.GL_DEPTH_TEST)
    earth.draw(gl.GL_TRIANGLES, indices)
    paths.draw()
    gl.glDisable(gl.GL_DEPTH_TEST)
Esempio n. 5
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()
Esempio n. 6
0
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
for i, y in enumerate(np.linspace(xmin, xmax, n)):
    text = "%.2f" % (i / 10.0)
    labels.append(text,
                  regular,
                  origin=(1.05, y, z),
                  scale=scale,
                  direction=(1, 0, 0),
                  anchor_x="left",
                  anchor_y="center")
    labels.append(text,
                  regular,
                  origin=(y, -1.05, z),
Esempio n. 7
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
        x = -2.5*2.6
    if name not in ["Brown", "Grey"]:
        names  = list(color.get(family).keys())[:-1][::-1]
        values = color.get(family+":*")[:-4][::-1]
    else:
        names  = list(color.get(family).keys())[::-1]
Esempio n. 8
0
def grid(transform, viewport, scale=1.0):
    ticks = SegmentCollection(mode="agg",
                              transform=transform,
                              viewport=viewport,
                              linewidth='local',
                              color='local')
    labels = GlyphCollection(transform=transform, viewport=viewport)
    # xmin,xmax = 0,800
    # ymin,ymax = 0,800
    xmin, xmax = -1, 1
    nx = 11
    dx = (xmax - xmin) / (nx - 1)
    ymin, ymax = -1, 1
    ny = 11
    dy = (ymax - ymin) / (ny - 1)

    z = 0

    regular = FontManager.get("OpenSans-Regular.ttf")
    bold = FontManager.get("OpenSans-Bold.ttf")

    labels_scale = 0.001
    for x in np.linspace(xmin, xmax, nx):
        text = "%.2f" % (x * scale)
        labels.append(text,
                      regular,
                      origin=(x, ymin - dy / 2, z),
                      scale=labels_scale,
                      direction=(1, 0, 0),
                      anchor_x="center",
                      anchor_y="top")

    for y in np.linspace(ymin, ymax, ny):
        text = "%.2f" % (y * scale)
        labels.append(text,
                      regular,
                      origin=(xmin - dx / 2, y, z),
                      scale=labels_scale,
                      direction=(1, 0, 0),
                      anchor_x="right",
                      anchor_y="center")

    title = "H3M example"
    labels.append(title,
                  bold,
                  origin=(0, xmax + dx, z),
                  scale=2 * labels_scale,
                  direction=(1, 0, 0),
                  anchor_x="center",
                  anchor_y="center")

    # Frame
    # -------------------------------------
    P0 = [(xmin, ymin, z), (xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z)]
    P1 = [(xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z), (xmin, ymin, z)]
    ticks.append(P0, P1, linewidth=2)

    # Grids
    # -------------------------------------
    n = 11
    P0 = np.zeros((n - 2, 3))
    P1 = np.zeros((n - 2, 3))

    P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1]
    P0[:, 1] = ymin
    P0[:, 2] = z
    P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1]
    P1[:, 1] = ymax
    P1[:, 2] = z
    ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, .25))

    P0 = np.zeros((n - 2, 3))
    P1 = np.zeros((n - 2, 3))
    P0[:, 0] = xmin
    P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1]
    P0[:, 2] = z
    P1[:, 0] = xmax
    P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1]
    P1[:, 2] = z
    ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, .25))

    # Majors
    # -------------------------------------
    n = 11
    P0 = np.zeros((n - 2, 3))
    P1 = np.zeros((n - 2, 3))
    P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1]
    P0[:, 1] = ymin - 0.015
    P0[:, 2] = z
    P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1]
    P1[:, 1] = ymin + 0.025 * (ymax - ymin)
    P1[:, 2] = z
    ticks.append(P0, P1, linewidth=1.5)
    P0[:, 1] = ymax + 0.015
    P1[:, 1] = ymax - 0.025 * (ymax - ymin)
    ticks.append(P0, P1, linewidth=1.5)

    P0 = np.zeros((n - 2, 3))
    P1 = np.zeros((n - 2, 3))
    P0[:, 0] = xmin - 0.015
    P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1]
    P0[:, 2] = z
    P1[:, 0] = xmin + 0.025 * (xmax - xmin)
    P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1]
    P1[:, 2] = z
    ticks.append(P0, P1, linewidth=1.5)
    P0[:, 0] = xmax + 0.015
    P1[:, 0] = xmax - 0.025 * (xmax - xmin)
    ticks.append(P0, P1, linewidth=1.5)

    # Minors
    # -------------------------------------
    n = 111
    P0 = np.zeros((n - 2, 3))
    P1 = np.zeros((n - 2, 3))
    P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1]
    P0[:, 1] = ymin
    P0[:, 2] = z
    P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1]
    P1[:, 1] = ymin + 0.0125 * (ymax - ymin)
    P1[:, 2] = z
    ticks.append(P0, P1, linewidth=1)
    P0[:, 1] = ymax
    P1[:, 1] = ymax - 0.0125 * (ymax - ymin)
    ticks.append(P0, P1, linewidth=1)

    P0 = np.zeros((n - 2, 3))
    P1 = np.zeros((n - 2, 3))
    P0[:, 0] = xmin
    P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1]
    P0[:, 2] = z
    P1[:, 0] = xmin + 0.0125 * (xmax - xmin)
    P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1]
    P1[:, 2] = z
    ticks.append(P0, P1, linewidth=1)
    P0[:, 0] = xmax
    P1[:, 0] = xmax - 0.0125 * (xmax - xmin)
    ticks.append(P0, P1, linewidth=1)
    return ticks
Esempio n. 9
0
"Came whiffling through the tulgey wood,\n"
"  And burbled as it came!\n"
"One, two! One, two! And through and through\n"
"  The vorpal blade went snicker-snack!\n"
"He left it dead, and with its head\n"
"  He went galumphing back.\n"
"\"And, has thou slain the Jabberwock?\n"
"  Come to my arms, my beamish boy!\n"
"O frabjous day! Callooh! Callay!'\n"
"  He chortled in his joy.\n"
"\n"
"`Twas brillig, and the slithy toves\n"
"  Did gyre and gimble in the wabe;\n"
"All mimsy were the borogoves,\n"
"  And the mome raths outgrabe.\n" )

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

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

glyphs = GlyphCollection(transform=Trackball(Position()))
glyphs.append(jabberwocky, FontManager.get("Roboto-Regular.ttf"))

window.attach(glyphs["transform"])
window.attach(glyphs["viewport"])

app.run()
Esempio n. 10
0
    uniform sampler2D texture;
    varying vec2 v_texcoord;
    void main()
    {
        gl_FragColor = texture2D(texture, v_texcoord);
    }
"""

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

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

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)]
log.info("Caching texture fonts")

manager = FontManager()

for size in range(8,25):
    font = manager.get("OpenSans-Regular.ttf", size=size, mode='agg')
    font.load(""" !\"#$%&'()*+,-./0123456789:;<=>?"""
              """@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"""
              """`abcdefghijklmnopqrstuvwxyz{|}~""")

program['texture'] = manager.atlas_agg
app.run()
Esempio n. 11
0
               "One, two! One, two! And through and through\n"
               "  The vorpal blade went snicker-snack!\n"
               "He left it dead, and with its head\n"
               "  He went galumphing back.\n"
               "\"And, has thou slain the Jabberwock?\n"
               "  Come to my arms, my beamish boy!\n"
               "O frabjous day! Callooh! Callay!'\n"
               "  He chortled in his joy.\n"
               "\n"
               "`Twas brillig, and the slithy toves\n"
               "  Did gyre and gimble in the wabe;\n"
               "All mimsy were the borogoves,\n"
               "  And the mome raths outgrabe.\n")

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


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


glyphs = GlyphCollection(transform=Trackball(Position()))
glyphs.append(jabberwocky, FontManager.get("Roboto-Regular.ttf"))

window.attach(glyphs["transform"])
window.attach(glyphs["viewport"])

app.run()
Esempio n. 12
0
# -----------------------------------------------------------------------------
# Copyright (c) 2009-2016 Nicolas P. Rougier. All rights reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
from glumpy import app, gl, gloo, glm, data
from glumpy.graphics.text import FontManager
from glumpy.graphics.collections import GlyphCollection
from glumpy.transforms import Position, OrthographicProjection

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

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

x,y,z = 256,256,0
font = FontManager.get("OpenSans-Regular.ttf", 64, mode='agg')
label = GlyphCollection('agg', transform=OrthographicProjection(Position()))
label.append("Hello World !", font,
                   anchor_x = 'center', anchor_y = 'center',
                   origin=(x,y,z), color=(1,1,1,1))

window.attach(label["transform"])

app.run()
Esempio n. 13
0
               "He left it dead, and with its head\n"
               "  He went galumphing back.\n"
               "\"And, has thou slain the Jabberwock?\n"
               "  Come to my arms, my beamish boy!\n"
               "O frabjous day! Callooh! Callay!'\n"
               "  He chortled in his joy.\n"
               "\n"
               "`Twas brillig, and the slithy toves\n"
               "  Did gyre and gimble in the wabe;\n"
               "All mimsy were the borogoves,\n"
               "  And the mome raths outgrabe.\n")

window = app.Window(width=700, height=700, title="hello", color=(1, 1, 1, 1))


@window.event
def on_draw(dt):

    window.clear()

    glyphs.draw()


glyphs = GlyphCollection(transform=Trackball(Position()))

glyphs.append(jabberwocky, FontManager.get("c:/windows/fonts/arial.ttf"))

window.attach(glyphs["transform"])
window.attach(glyphs["viewport"])

app.run()
Esempio n. 14
0
    uniform sampler2D texture;
    varying vec2 v_texcoord;
    void main()
    {
        gl_FragColor = texture2D(texture, v_texcoord);
    }
"""

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

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

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)]
log.info("Caching texture fonts")

manager = FontManager()

for size in range(8,25):
    font = manager.get("OpenSans-Regular.ttf", size=size, mode='agg')
    font.load(""" !\"#$%&'()*+,-./0123456789:;<=>?"""
              """@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"""
              """`abcdefghijklmnopqrstuvwxyz{|}~""")

program['texture'] = manager.atlas_agg
app.run()