Drawbot on something more powerful than desktops and laptops?



  • Has anyone heard of DrawBot running on a machine faster and with more memory than laptop and desktop machines? Is that machine yours, or are you close to it? I've got some ambitious animations I'd love to generate, but they're way beyond anything the machines I have access to could handle.



  • @mauricemeilleur Before you consider heavier hardware, consider whether you currently get the most out of your available computing power.

    Python doesn't utilize multiple cores, so running several processes simultaneuously can speed up things. Easiest to do this would be to run DrawBot as a module, and fire up command line scripts from Terminal. This way one could theoretically get a 4x speedup on a 4-core CPU, although in practice, some recent eperiments I did shows this may be limited to roughly a 2x speedup (possibly due to an IO bottleneck).

    Make sure you generate each frame as a new drawing, and save to disk as png, to avoid building up a huge multi page PDF in memory. Use this pattern:

    numFrames = 10
    for frame in range(numFrames):
        newDrawing()  # start from scratch, no multipage
        newPage(500, 500)
        # ... draw your frame
        saveImage("myimagefolder/myimage%d.png" % frame)
    

    Also, once it's running in Terminal, it shouldn't be in your way much (especially if you use only one process so you don't max out all available cores), and just let it compute, for hours, or days...

    To convert the image sequence to mp4, use something like:

    from drawBot.context.tools.mp4Tools import generateMP4
    
    frameRate = 25
    generateMP4("myimagefolder/myimage%d.png", "output.mp4", frameRate)
    

    Consider running this in Terminal also, so it won't block your DrawBot app.



  • So I'd be running the code as a script in Terminal?

    python3 path/to/my/script.py
    

    And if I already had the separate frames as images, that script only needs to import generateMP4 and make the video—so just those three lines of code you wrote?



  • @mauricemeilleur Yes, to both questions. However, it requires you to have drawBot (and its dependencies) installed as an importable module. See the readme at https://github.com/typemytype/drawbot

    Once you have that set up, learn how to use command line arguments to pass info to your script:

    python path/to/my/script.py 3
    

    In the script:

    import sys
    startFrame = int(sys.argv[1])
    print(startFrame)
    


  • Thanks—I'll have a chance to try this for myself later today.