Ejemplo n.º 1
0
    import OpenGL.GLUT as glut

    from glagg import curve4_bezier
    from glagg import PathCollection

    t0, frames = glut.glutGet(glut.GLUT_ELAPSED_TIME), 0
    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(800, 800)
    glut.glutCreateWindow("Shapes")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutIdleFunc(on_idle)

    collection = PathCollection()
    def heart():
        vertices = curve4_bezier( (0.0,-0.5), (0.75,+0.25), (.75,+1.0), (0.0,+0.5) )
        n = len(vertices)
        V = np.zeros((2*n,2))
        V[:n] = vertices
        V[n:] = vertices[::-1]
        V[n:,0] *=-1
        V[n:,0] -= .0001
        return V

    vertices = heart()
    for i in range(2000):
        color = np.random.uniform(0,1,4)
        linewidth = 1
        translate = np.random.uniform(0,1,2)
Ejemplo n.º 2
0
    import OpenGL.GLUT as glut

    from glagg import curve4_bezier
    from glagg import PathCollection

    t0, frames = glut.glutGet(glut.GLUT_ELAPSED_TIME), 0
    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
    glut.glutCreateWindow("Shapes")
    glut.glutReshapeWindow(800, 800)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutIdleFunc(on_idle)

    collection = PathCollection()
    def heart():
        vertices = curve4_bezier( (0.0,-0.5), (0.75,+0.25), (.75,+1.0), (0.0,+0.5) )
        n = len(vertices)
        V = np.zeros((2*n,2))
        V[:n] = vertices
        V[n:] = vertices[::-1]
        V[n:,0] *=-1
        V[n:,0] -= .0001
        return V

    vertices = heart()
    for i in range(2000):
        color = np.random.uniform(0,1,4)
        linewidth = 1
        translate = np.random.uniform(0,800,2)
Ejemplo n.º 3
0
    from glagg import DashAtlas

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB
                             | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(512, 512)
    glut.glutCreateWindow(
        "Dashed & antialiased bezier curve [Arrow keys change offset]")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutSpecialFunc(on_special)

    atlas = DashAtlas()
    atlas['custom'] = (.1, .1), (1, 1)
    collection = PathCollection(atlas)

    # ---------------------------------
    points = np.array([[.1, .6], [.5, 1.], [.9, .6]])
    vertices = curve3_bezier(*points)
    collection.append(vertices,
                      color=(0.75, 0.75, 1.00, 1.00),
                      linewidth=40,
                      dash_pattern='densely dashed')

    # ---------------------------------
    vertices = curve3_bezier(*(points + [0, -0.3]))
    collection.append(vertices,
                      color=(0.75, 0.75, 1.00, 1.0),
                      linewidth=50,
                      linecaps=('|', '|'),
Ejemplo n.º 4
0
def on_reshape(width, height):
    gl.glViewport(0, 0, width, height)

# -------------------------------------
def on_keyboard(key, x, y):
    if key == '\033': sys.exit()


# -----------------------------------------------------------------------------
if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut
    from shapes import star, asterisk
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutInitWindowSize(800, 800)
    glut.glutCreateWindow("Error case 1")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    collection = PathCollection()
    vertices = star(n=25)
    collection.append( vertices, closed=True, linewidth=15, color = (0,0,0,1),
                       linejoin = 'miter', miter_limit=15.0,
                       translate=(400,400), scale=300)

    glut.glutMainLoop()
Ejemplo n.º 5
0
    from glagg import PathCollection
    from shapes import star, asterisk

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB
                             | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(512, 512)
    glut.glutCreateWindow("Dashed stars")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutIdleFunc(on_idle)

    t0, frames, t = 0, 0, 0
    t0 = glut.glutGet(glut.GLUT_ELAPSED_TIME)

    collection = PathCollection()
    vertices = star(n=5)
    for i in range(2000):
        collection.append(vertices,
                          closed=True,
                          color=np.random.uniform(0, 1, 4),
                          linewidth=np.random.uniform(1, 2),
                          translate=np.random.uniform(0, 1, 2),
                          scale=np.random.uniform(10, 15),
                          rotate=np.random.uniform(0, 2 * np.pi),
                          dash_pattern='dotted')
    positions = collection.translate.copy()
    glut.glutMainLoop()
Ejemplo n.º 6
0
    import sys
    import OpenGL.GLUT as glut
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutInitWindowSize(1000, 800)
    glut.glutCreateWindow("Antialiased thick polylines")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    V = np.array([[-.1, 0.], [.0, +1.], [+.1, 0.]])
    xmin, xmax = V[:, 0].min(), V[:, 0].max()
    ymin, ymax = V[:, 1].min(), V[:, 1].max()
    V[:, 0] -= (xmax + xmin) / 2.0
    V[:, 1] -= (ymax + ymin) / 2.0

    collection = PathCollection()
    collection.append(V,
                      closed=False,
                      translate=(500, 400),
                      scale=100,
                      color=(0, 0, 0, 1),
                      linewidth=50,
                      antialias=1,
                      linejoin='round',
                      miter_limit=4.0,
                      linecaps=('square', 'square'))
    glut.glutMainLoop()
Ejemplo n.º 7
0
    from shapes import star, asterisk

    t0, frames, t = 0,0,0
    t0 = glut.glutGet(glut.GLUT_ELAPSED_TIME)

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB |
                             glut.GLUT_DEPTH  | glut.GLUT_STENCIL )
    glut.glutInitWindowSize(800, 800)
    glut.glutCreateWindow("Clipping demo")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutIdleFunc(on_idle)

    collection = PathCollection()
    mask = PathCollection()
    size = 800

    collection.clear()
    vertices = star(n=5)
    for i in range(2000):
        collection.append(
            vertices, closed=True,
            color = np.random.uniform(0,1,4),
            linewidth = np.random.uniform(1,2),
            translate = np.random.uniform(0,1,2),
            scale = np.random.uniform(10,15),
            rotate = np.random.uniform(0,2*np.pi))
    positions = collection.translate.copy()
Ejemplo n.º 8
0
        sys.exit()


# -----------------------------------------------------------------------------
if __name__ == "__main__":
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutInitWindowSize(600, 256)
    glut.glutCreateWindow("Antialiased lines")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    collection = PathCollection()
    for i in range(68):
        color = 0, 0, 0, 1
        linewidth = 0.1 + i * 0.1
        scale = 200
        theta = -5 * np.pi / 180
        translate = 32 + i * 8, 128
        collection.append(
            [(0.0, -0.5), (0.0, +0.5)],
            closed=False,
            linewidth=linewidth,
            color=color,
            scale=scale,
            rotate=theta,
            translate=translate,
        )
Ejemplo n.º 9
0
if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutInitWindowSize(512, 512)
    glut.glutCreateWindow("Line joins")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutSpecialFunc(on_special)

    vertices = np.array( [(-0.50,-0.125),
                          (-0.25,+0.125),
                          (+0.00,-0.125),
                          (+0.25,+0.125),
                          (+0.50,-0.125) ] )
    collection = PathCollection()
    collection.append(vertices, linewidth = 40,
                      linejoin = 'miter', linecaps= ('<','>'),
                      scale = 300, translate = (256,128) )
    collection.append(vertices, linewidth = 40,
                      linejoin = 'round', linecaps= ('(',')'),
                      scale = 300, translate = (256,256) )
    collection.append(vertices, linewidth = 40,
                      linejoin = 'bevel', linecaps= ('=','='),
                      scale = 300, translate = (256,384) )
    glut.glutMainLoop()
Ejemplo n.º 10
0
    scale = 1.

    # For OSX, see https://github.com/nanoant/osxglut
    # GLUT for Mac OS X fork with Core Profile and scroll wheel support
    try:
        from ctypes import c_float
        from OpenGL.GLUT.special import GLUTCallback
        glutScrollFunc = GLUTCallback(
            'Scroll', (c_float,c_float), ('delta_x','delta_y'),)
        glutScrollFunc(on_scroll)
    except:
        if bool(glut.glutMouseWheelFunc):
            glut.glutMouseWheelFunc(on_wheel)


    collection = PathCollection()
    def dist(v0,v1):
        x0,y0 = v0
        x1,y1 = v1
        dx,dy = (x1-x0), (y1-y0)
        return dx*dx+dy*dy

    vertices = svg_open('data/tiger.svg')
    for V in vertices:
        closed = dist(V[0],V[-1]) < 1e-10
        V = np.array(V)
        V[:,1] = -V[:,1]
        collection.append(V, closed=closed, linewidth=scale/4.0,
                          translate=translate, scale=scale,
                          dash_pattern = 'loosely dashed')
Ejemplo n.º 11
0
if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut
    from shapes import star, asterisk
    from glagg import PathCollection

    t0, frames, t = 0,0,0
    t0 = glut.glutGet(glut.GLUT_ELAPSED_TIME)

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(512, 512)
    glut.glutCreateWindow("Antialiased thick polylines")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutIdleFunc(on_idle)

    vertices = np.array( [(+0.0,+0.5), (+0.0,-0.5)] )
    collection = PathCollection()
    for i in range(500):
        theta = i*(5.5/180.0*np.pi)
        radius = 255-i*0.45
        x = 256 + np.cos(theta)*radius
        y = 256 + np.sin(theta)*radius
        scale = 20-15*i/float(500)
        collection.append(vertices, closed=False,
                          scale = scale, rotate = theta + np.pi/2, translate = (x,y),
                          dash_pattern = 'loosely dotted' )
    glut.glutMainLoop()
Ejemplo n.º 12
0
    # For OSX, see https://github.com/nanoant/osxglut
    # GLUT for Mac OS X fork with Core Profile and scroll wheel support
    try:
        from ctypes import c_float
        from OpenGL.GLUT.special import GLUTCallback
        glutScrollFunc = GLUTCallback(
            'Scroll',
            (c_float, c_float),
            ('delta_x', 'delta_y'),
        )
        glutScrollFunc(on_scroll)
    except:
        if bool(glut.glutMouseWheelFunc):
            glut.glutMouseWheelFunc(on_wheel)

    collection = PathCollection()

    def dist(v0, v1):
        x0, y0 = v0
        x1, y1 = v1
        dx, dy = (x1 - x0), (y1 - y0)
        return dx * dx + dy * dy

    vertices = svg_open('data/tiger.svg')
    for V in vertices:
        closed = dist(V[0], V[-1]) < 1e-10
        V = np.array(V)
        V[:, 1] = -V[:, 1]
        collection.append(V,
                          closed=closed,
                          linewidth=scale / 4.0,
Ejemplo n.º 13
0
# -------------------------------------
def on_keyboard(key, x, y):
    if key == '\033': sys.exit()
    if key == ' ': fbo.save( on_display, "gl-spiral.png")

# -----------------------------------------------------------------------------
if __name__ == '__main__':
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutCreateWindow("OpenGL antialiased spiral")
    glut.glutReshapeWindow(512, 512+32)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    collection = PathCollection()
    vertices=[]
    
    n = 2000
    angles = np.linspace(0,18*2*np.pi, n)
    radii  = np.linspace(1,228, n)
    for angle,radius in zip(angles,radii):
        x,y = radius*np.cos(angle), radius*np.sin(angle)
        vertices.append((x+256,y+256+32))
    collection.append(vertices)

    glut.glutMainLoop()
Ejemplo n.º 14
0
    from shapes import star, asterisk

    t0, frames, t = 0, 0, 0
    t0 = glut.glutGet(glut.GLUT_ELAPSED_TIME)

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH
                             | glut.GLUT_STENCIL)
    glut.glutInitWindowSize(800, 800)
    glut.glutCreateWindow("Clipping demo")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutIdleFunc(on_idle)

    collection = PathCollection()
    mask = PathCollection()
    size = 800

    collection.clear()
    vertices = star(n=5)
    for i in range(2000):
        collection.append(vertices,
                          closed=True,
                          color=np.random.uniform(0, 1, 4),
                          linewidth=np.random.uniform(1, 2),
                          translate=np.random.uniform(0, 1, 2),
                          scale=np.random.uniform(10, 15),
                          rotate=np.random.uniform(0, 2 * np.pi))
    positions = collection.translate.copy()
Ejemplo n.º 15
0

# -----------------------------------------------------------------------------
if __name__ == '__main__':
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutCreateWindow("OpenGL antialiased lines")
    glut.glutReshapeWindow(512, 512 + 32)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    vertices = np.array([(+0.0, +0.5), (+0.0, -0.5)])
    collection = PathCollection()
    for i in range(500):
        theta = i * (5.5 / 180.0 * np.pi)
        radius = 255 - i * 0.45
        x = 256 + np.cos(theta) * radius
        y = 256 + np.sin(theta) * radius + 32
        scale = 20 - 15 * i / float(500)
        collection.append(vertices,
                          closed=False,
                          translate=(x, y),
                          scale=scale,
                          rotate=theta + np.pi / 2)
    for i in range(0, 49):
        linewidth = (i + 1) / 10.0
        collection.append([(20 + i * 10 + .315, 10), (20 + i * 10 + .315, 22)],
                          linewidth=linewidth)
Ejemplo n.º 16
0
    from glagg import curve3_bezier, curve4_bezier
    from glagg import PathCollection
    from glagg import DashAtlas

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(512, 512)
    glut.glutCreateWindow("Dashed & antialiased bezier curve [Arrow keys change offset]")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutSpecialFunc(on_special)

    atlas = DashAtlas()
    atlas['custom'] = (.1,.1), (1,1)
    collection = PathCollection( atlas )

    # ---------------------------------
    points = np.array([[.1, .6], [.5, 1.], [.9, .6]])
    vertices = curve3_bezier(*points)
    collection.append(vertices, color=(0.75,0.75,1.00,1.00), linewidth=40,
                      dash_pattern = 'densely dashed')

    # ---------------------------------
    vertices = curve3_bezier(*(points + [0, -0.3]))
    collection.append( vertices, color=(0.75,0.75,1.00,1.0),
                       linewidth=50,  linecaps = ('|','|'),
                       dash_pattern = 'custom', dash_caps=('|','|') )

    glut.glutMainLoop()
Ejemplo n.º 17
0
    if key == '\033': sys.exit()


# -----------------------------------------------------------------------------
if __name__ == '__main__':
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutInitWindowSize(600, 256)
    glut.glutCreateWindow("Antialiased lines")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    collection = PathCollection()
    for i in range(68):
        color = 0, 0, 0, 1
        linewidth = .1 + i * .1
        scale = 200
        theta = -5 * np.pi / 180
        translate = 32 + i * 8, 128
        collection.append([(0.0, -0.5), (0.0, +0.5)],
                          closed=False,
                          linewidth=linewidth,
                          color=color,
                          scale=scale,
                          rotate=theta,
                          translate=translate)
    glut.glutMainLoop()
Ejemplo n.º 18
0
if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut
    from shapes import star, asterisk
    from glagg import PathCollection

    t0, frames, t = 0,0,0
    t0 = glut.glutGet(glut.GLUT_ELAPSED_TIME)

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
    glut.glutCreateWindow("Antialiased thick polylines")
    glut.glutReshapeWindow(512, 512)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutIdleFunc(on_idle)

    vertices = np.array( [(+0.0,+0.5), (+0.0,-0.5)] )
    collection = PathCollection()
    for i in range(500):
        theta = i*(5.5/180.0*np.pi)
        radius = 255-i*0.45
        x = 256 + np.cos(theta)*radius
        y = 256 + np.sin(theta)*radius
        scale = 20-15*i/float(500)
        collection.append(vertices, closed=False,
                          scale = scale, rotate = theta + np.pi/2, translate = (x,y),
                          dash_pattern = 'loosely dotted' )
    glut.glutMainLoop()
Ejemplo n.º 19
0
    if key == ' ': fbo.save( on_display, "gl-lines.png")

# -----------------------------------------------------------------------------
if __name__ == '__main__':
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutCreateWindow("OpenGL antialiased lines")
    glut.glutReshapeWindow(512, 512+32)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    vertices = np.array( [(+0.0,+0.5), (+0.0,-0.5)] )
    collection = PathCollection()
    for i in range(500):
        theta = i*(5.5/180.0*np.pi)
        radius = 255-i*0.45
        x = 256 + np.cos(theta)*radius
        y = 256 + np.sin(theta)*radius + 32
        scale = 20-15*i/float(500)
        collection.append(vertices, closed=False, translate = (x,y),
                          scale = scale, rotate = theta + np.pi/2)
    for i in range(0,49):
        linewidth = (i+1)/10.0
        collection.append( [(20+i*10+.315,10),(20+i*10+.315,22)], linewidth=linewidth)


    glut.glutMainLoop()
Ejemplo n.º 20
0
    from shapes import star, asterisk

    t0, frames, t = 0,0,0
    t0 = glut.glutGet(glut.GLUT_ELAPSED_TIME)

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB |
                             glut.GLUT_DEPTH  | glut.GLUT_STENCIL )
    glut.glutCreateWindow("Clipping demo")
    glut.glutReshapeWindow(800, 800)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutIdleFunc(on_idle)

    collection = PathCollection()
    vertices = star(n=5)
    for i in range(2000):
        collection.append(
            vertices, closed=True,
            color = np.random.uniform(0,1,4),
            linewidth = np.random.uniform(1,2),
            translate = np.random.uniform(0,800,2),
            scale = np.random.uniform(10,15),
            rotate = np.random.uniform(0,2*np.pi))

    mask = PathCollection()
    mask.append( vertices, closed=True,
                 color = (0,0,0,1), linewidth=100, translate=(400,400), scale=300)

    glut.glutMainLoop()
Ejemplo n.º 21
0
if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutInitWindowSize(1000, 800)
    glut.glutCreateWindow("Antialiased thick polylines")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)


    V = np.array([[-.1, 0.],
                  [ .0, +1.],
                  [+.1, 0.]])
    xmin,xmax = V[:,0].min(),V[:,0].max()
    ymin,ymax = V[:,1].min(),V[:,1].max()
    V[:,0] -= (xmax+xmin)/2.0
    V[:,1] -= (ymax+ymin)/2.0

    collection = PathCollection()
    collection.append(V, closed=False, translate = (500,400),
                      scale = 100, color=(0,0,0,1),
                      linewidth=50, antialias=1,
                      linejoin='round', miter_limit=4.0,
                      linecaps=('square','square'))
    glut.glutMainLoop()
Ejemplo n.º 22
0
    circles.append( center = p3, radius = 4, fg_color=(0.0,0.0,1.0,1.0) )


# -----------------------------------------------------------------------------
if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut

    from glagg import curve3_bezier, curve4_bezier
    from glagg import PathCollection, CircleCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(800, 800)
    glut.glutCreateWindow("Dynamic cubic Bézier curve [drag handles with mouse]")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutMouseFunc(on_mouse)
    glut.glutMotionFunc(on_motion)
    glut.glutPassiveMotionFunc(on_passive_motion)

    paths = PathCollection()
    circles = CircleCollection()
    drag,index = False, -1
    points = np.array( [ (100.,400.), (400.,700.),
                         (500.,100.), (700.,400.) ] )
    add_bezier(*points)

    glut.glutMainLoop()
Ejemplo n.º 23
0
if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutCreateWindow("Line joins")
    glut.glutReshapeWindow(512, 512)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutSpecialFunc(on_special)

    vertices = np.array( [(-0.50,-0.125),
                          (-0.25,+0.125),
                          (+0.00,-0.125),
                          (+0.25,+0.125),
                          (+0.50,-0.125) ] )
    collection = PathCollection()
    collection.append(vertices, linewidth = 40,
                      linejoin = 'miter', linecaps= ('<','>'),
                      scale = 300, translate = (256,128) )
    collection.append(vertices, linewidth = 40,
                      linejoin = 'round', linecaps= ('(',')'),
                      scale = 300, translate = (256,256) )
    collection.append(vertices, linewidth = 40,
                      linejoin = 'bevel', linecaps= ('=','='),
                      scale = 300, translate = (256,384) )
    glut.glutMainLoop()
Ejemplo n.º 24
0
# -----------------------------------------------------------------------------
if __name__ == '__main__':
    import re
    import xml.dom
    import xml.dom.minidom
    from glagg import Path, PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutCreateWindow("SVG Tiger")
    glut.glutReshapeWindow(512, 512 + 32)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    collection = PathCollection()

    def dist(v0, v1):
        x0, y0 = v0
        x1, y1 = v1
        dx, dy = (x1 - x0), (y1 - y0)
        return dx * dx + dy * dy

    vertices = svg_open('tiger.svg')
    for V in vertices:
        closed = dist(V[0], V[-1]) < 1e-10
        V = np.array(V)
        V[:, 1] = -V[:, 1]
        V += (180, 380)
        collection.append(V, closed=closed, linewidth=.25)
Ejemplo n.º 25
0
if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut
    from shapes import star, asterisk
    from glagg import PathCollection

    t0, frames, t = 0,0,0
    t0 = glut.glutGet(glut.GLUT_ELAPSED_TIME)
    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(800, 800)
    glut.glutCreateWindow("Asterisks")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutIdleFunc(on_idle)

    collection = PathCollection()
    vertices = asterisk(n=5)

    for i in range(2000):
        collection.append(
            vertices, closed=True,
            color = np.random.uniform(0,1,4),
            linewidth = np.random.uniform(1,2),
            translate = np.random.uniform(0,1,2),
            scale = np.random.uniform(10,15),
            rotate = np.random.uniform(0,2*np.pi))
    positions = collection.translate.copy()
    glut.glutMainLoop()
Ejemplo n.º 26
0
    return np.array(points).reshape(n, 2)


# -----------------------------------------------------------------------------
if __name__ == '__main__':
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutCreateWindow("OpenGL antialiased stars")
    glut.glutReshapeWindow(512, 512 + 32)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    collection = PathCollection()
    s = star()
    radius = 255.0
    theta, dtheta = 0, 5.5 / 180.0 * np.pi
    for i in range(500):
        theta += dtheta
        x = 256 + radius * np.cos(theta)
        y = 256 + 32 + radius * np.sin(theta)
        r = 10.1 - i * 0.02
        radius -= 0.45
        collection.append(s * r + (x, y), closed=True, linejoin='miter')

    for i in range(0, 39):
        linewidth = (i + 1) / 20.0
        x = 20 + i * 12.5 - r
        y = 16
Ejemplo n.º 27
0
    return np.array(points).reshape(n,2)


# -----------------------------------------------------------------------------
if __name__ == '__main__':
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutCreateWindow("OpenGL antialiased stars")
    glut.glutReshapeWindow(512, 512+32)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)

    collection = PathCollection()
    s = star()
    radius = 255.0
    theta, dtheta = 0, 5.5/180.0*np.pi
    for i in range(500):
        theta += dtheta
        x = 256+radius*np.cos(theta)
        y = 256+32+radius*np.sin(theta)
        r = 10.1-i*0.02
        radius -= 0.45
        collection.append( s*r + (x,y), closed=True, linejoin='miter')

    for i in range(0,39):
        linewidth = (i+1)/20.0
        x = 20+i*12.5 - r
        y = 16
Ejemplo n.º 28
0
    elif key == glut.GLUT_KEY_RIGHT:
        collection.dash_phase += 0.05
    glut.glutPostRedisplay()

# -----------------------------------------------------------------------------
if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut
    from shapes import star
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutInitWindowSize(800, 800)
    glut.glutCreateWindow("Error case 1")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutSpecialFunc(on_special)

    collection = PathCollection()
    vertices = []
    for theta in np.linspace(0,2*np.pi,100,endpoint=False):
        x,y = 0.5*np.cos(theta), 0.5*np.sin(theta)
        vertices.append( (x,y) )
    #vertices = star(n=5)
    collection.append( vertices, closed=True, linewidth=25, color = (0,0,0,1),
                       dash_pattern = 'dashed', translate=(400,400), scale=400)

    glut.glutMainLoop()