Generating Fractal Images with Fractal Machine and PhantomJS

I wrote up a script to take screenshots of randomized images from Fractal Machine, which is a really cool fractal generator. To run this, I would a local copy of the html file for the site, otherwise you’ll be generating a lot of needless load on their side.

var page = require('webpage').create();
page.viewportSize = { width: 400, height: 400 };

var num = 0;
var system = require('system');
if (system.args.length > 1) {
  num = system.args[1];
}

function waitFor(testFx, onReady, timeOutMillis) {
    var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 50,
        start = new Date().getTime(),
        condition = false,
        interval = setInterval(function () {
            if1; //< defensive code
            } else {
                if (!condition) {
                    typeof (onReady) === "string" ? eval(onReady) : onReady();
                    clearInterval(interval);
                } else {
                    console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
                    typeof (onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
                    clearInterval(interval); //< Stop this interval
                }
            }
        }, 50); 
};

page.open('fractalmachine.html', function () {
  waitFor(
    function () {
      return page.evaluate(function () {
        return window.document.getElementById('controls') != undefined;
      });
    },
    function () {
      page.evaluate(function() {
        var fract = window.fract;
        fract.random();
        fract.zoomnudge(-1);
        var controls = window.document.getElementById('controls');
        controls.style.visibility = 'hidden';
      });
      page.render('fractal' + num + '.png');
      phantom.exit();
    }, 50);
  });

fractal

fractal0

fractal1

fractal3

fractal5

fractal6

fractal8

fractal9

fractal11

fractal12

fractal16

fractal23

fractal25

fractal27

fractal29

fractal30

fractal31

fractal34

fractal35

fractal37

fractal38

fractal39

fractal41

fractal43

fractal44

fractal46

fractal47

fractal50

fractal52

fractal53

fractal57

fractal58

fractal63

fractal67

fractal68

fractal69

fractal70

fractal71

fractal72

fractal74

fractal76

fractal77

fractal78

fractal80

fractal82

fractal84

fractal85

fractal86

fractal87

fractal88

fractal90

fractal91

fractal92

fractal93

fractal97

fractal98

fractal99

fractal100

fractal101

fractal102

fractal105

fractal106

fractal107

fractal109

fractal110

fractal112

fractal114

fractal115

fractal116

fractal117

fractal119

fractal120

fractal122

  1. new Date().getTime() - start < maxtimeOutMillis) && !condition) { condition = (typeof (testFx) === "string" ? eval(testFx) : testFx( []