News for hackers. Stuff that matters.
Re:Ask HN: What do you use for programmatic drawing? by tmaly on Thursday November 11, 2021 @03:19PM (#29192634)
For Python you could use the pyglet OpenGL library to do both 2D and 3D https://github.com/pyglet/pyglet

For Scratch, the pen tool extension works really well. I was just doing a demo on this for an elementary class the other day.

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()
Re:Ask HN: What do you use for programmatic drawing? by scotty79 on Friday November 12, 2021 @03:51AM (#29197413)
After some experimentation I found out that pygame is even better them pyglet.

I had multiple issues with pyglet with high monitor refresh rate, HDR and refresh rate mysteriously slowing down after I dragged the window around. While pygame works flawlessly.