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
# 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. 3
0
@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
Esempio n. 4
0
@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")
Esempio n. 5
0
    gl_Position = <transform(origin)>;
    v_color = color;
    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()
Esempio n. 6
0
# -----------------------------------------------------------------------------
from glumpy import app
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(transform=OrthographicProjection(Position()))
regular = FontManager.get("OpenSans-Regular.ttf")
text = "The quick brown fox jumps over the lazy dog"
x, y, z = 2, window.height, 0

for i in range(6, 54, 2):
    scale = i / 48.0
    y -= i * 1.1
    labels.append(text,
                  regular,
                  origin=(x, y, z),
                  scale=scale,
                  anchor_x="left")

window.attach(labels["transform"])
window.attach(labels["viewport"])
Esempio n. 7
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. 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
               "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
# -----------------------------------------------------------------------------
# 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. 11
0
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
from glumpy import app
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(transform=OrthographicProjection(Position()))
regular = FontManager.get("OpenSans-Regular.ttf")
text = "The quick brown fox jumps over the lazy dog"
x, y, z = 2, window.height, 0

for i in range(6, 54, 2):
    scale = i / 48.0
    y -= i * 1.1
    labels.append(text, regular, origin=(x, y, z), scale=scale, anchor_x="left")


window.attach(labels["transform"])
window.attach(labels["viewport"])
app.run()
Esempio n. 12
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()