## Sunday, February 5, 2012

### I hope you find this blog enjoyable and helpful. Support it with a small donation.

Over the last couple of weeks I've been trying to find a way to draw physics diagrams in a style similar to what I've seen in textbooks.  I was hoping for a vector based solution that was open source.  After a few false starts I gave Inkscape a go, but it was hard to get things looking right.  Then I came across Metapost which was close to what I wanted but it was a bit hard to draw 3D diagrams realistically.  Then I found Asymptote, which is inspired by Metapost and is generalised to 3D diagrams.  It's easy to use for someone with a little bit of maths knowledge and produces beautiful results.

As with learning any new language, it's extremely helpful if you have an efficient toolchain that allows you to focus on the job at hand and not on running commands to compile and render things.  The below video demonstrates an easy way to do this using inotifywait from the Inotify-tools package.

while true; do inotifywait -e CLOSE_WRITE $filename; asy -render 0$filename; done;

The command is straight forward.  An infinite while loop is started, and in it inotifywait is instructed to monitor a file for a CLOSE_WRITE condition, thereby blocking further execution.   When the condition is met the command to render the image is called.

This command could be useful in any situation where you need to monitor if a file is altered.  Anyway, back to learning Asymptote.