HTML Canvas string-rewriting fractal

I’d hoped to have a working demo in here, but WordPress doesn’t like the <canvas> element, so here are a couple of static screendumps:

looks like a buffalo being attacked by crinkle-cut chipsI wrote a routine in JavaScript that recursively rewrites strings of instructions, then interprets them as a simple turtle-like language to draw on the canvas. In my copious free time, I’ll release it as a simple web app that you can play with these L-systems. But you can do some fun stuff here until I get it written.

(for more details, see Appendix C of H. Peitgen and D. Saupe, Eds. The Science of Fractal Images, New York: Springer, 1988.)

sometimes you just have to …

… calculate the number of seconds in the current year using JavaScript:

function seconds_in_this_year() {
      // get length of this year by subtracting "Jan 1st, /This Year/"
      // from  "Jan 1st, /Next Year/"
      var now = new Date();
      var current_year = now.getFullYear();
      var jan_first = new Date(current_year, 0, 1, 0, 0, 0, 0);
      var jan_next = new Date(current_year + 1, 0, 1, 0, 0, 0, 0);
      return (jan_next.getTime() - jan_first.getTime()) / 1000;
}