1. 30
  1.  

  2. 5

    This is a neat hack, and since I’m sitting on a Mac for work right now, I wondered “Could I do this in AppleScript with TextEdit?” Well, I figured out how to manipulate the text, and then when clicking around in Script Editor, I realized “OH MY, I CAN USE JAVASCRIPT.” I don’t have time right now to port one of my little ray tracers to JavaScript to test this theory, and it’s certainly the case that we’d need to adjust the font to monospace and such in the script… but in case anyone is wondering, or wants to build off of it:

    var textEdit = Application("TextEdit");
    while (1) {
     var output = "";
     for (var i = 1; i <= 1000; i++) {
      if (Math.random() < .5) {
         output += "\\";
      }
      else {
         output += "/";
      }
      if (i % 100 == 0) {
         output += "\n";
      }
     }
     textEdit.documents[0].text = output;
    }
    

    This will generate the classic BASIC program that does the \ or / making a fun little pattern, in a 100x10 box. This same technique would easily work for a ray tracer if you implemented the math and shader.

    The one problem I need to investigate is how to make a monospace font stick. Some quick playing didn’t get me there, but did allow me to consistently crash Script Editor. I changed the last line to .text = textEdit.Text({"font": "Monaco"}, output) based on a whim from an unrelated Stack Overflow question. But, that crashes on the latest Mojave…