Sunday, February 5, 2012

An IDE for Asymptote using inotifywait

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.

3 comments:

  1. Hi,

    Thank you for your nice video. Can I have you source file (1.asy).

    Regards,
    -Hamid

    ReplyDelete
    Replies
    1. Glad you liked it. I don't have the exact source file that I used in the video, but I have the final version of that file that has a few more details. The code is a little bit rough around the edges and lacks detailed commenting but it's not that big a file and should be easy enough to figure out. Here is the address https://docs.google.com/open?id=0B5Hb04O3hlQSWmJiVGZUN0hURlk

      The final version of 1.asy was used to make this video http://www.grant-trebbin.com/2012/04/off-axis-magnetic-field-of-circular.html

      Delete