News for hackers. Stuff that matters.
Re:Ask HN: What do you use for programmatic drawing? by scotty79 on Thursday November 11, 2021 @03:55PM (#29193039)
Pyglet looks great, but drawing is done in OpenGL way.

Is there a libraray that uses pyglet giving it the drawing interface more limilar to what other 2d APIs offer? Like the one suppoted by HTML Canvas tag?

EDIT:

Never mind. I just noticed pyglet.shapes offers something more palatable than OpenGL. :-)

and doing stuff is pretty clean:

    import pyglet
    from pyglet import shapes

    batch = pyglet.graphics.Batch()

    circle = shapes.Circle(700, 150, 100, color=(50, 225, 30), batch=batch)
    square = shapes.Rectangle(200, 200, 200, 200, color=(55, 55, 255), batch=batch)

    window = pyglet.window.Window(960, 540)

    @window.event
    def on_draw():
        window.clear()
        batch.draw()

    @window.event
    def on_key_press(symbol, modifiers):
        if symbol == pyglet.window.key.ESCAPE:
            window.close()

    pyglet.app.run()

There are no comments on this comment yet.