scale = 4;//.25; // 4 is fast, .25 for hi-res video frames xDim = 1920 / scale; yDim = 1080 / scale; maxcircles = 2000;//32000; //2000 is enough for scale 4 dir = "\\VBOXSVR\windowsShare\circlePack\p"; // video frames ncircles = 0; center = J( maxcircles, 2, . ); radius = J( maxcircles, 1, 0 ); finish = J( maxcircles, 1, 0 ); New Window( "Example", g = Graph Box( <= maxcircles, Return() ); While( 1, c = Random Uniform( 0, xDim ) || Random Uniform( 0, yDim ); // crude hunt... For( i = 1, i <= ncircles, i++, // larger circles at front, not as bad as it could be If( Sqrt( Sum( (c - center[i, 0]) ^ 2 ) ) < radius[i], Break( /*try again, inside another circle*/ ) ) ); If( i > ncircles, //loop above finished checking OK, add it ncircles++; center[ncircles, 0] = c; radius[ncircles] = .5; Return(); ); ); Throw( "didn't expect that" ); ); nAlive = 0; growCircles = Function( {}, {i, j, c, r, td, r2, f}, nAlive = 0; For( i = 1, i <= ncircles, i++, r = radius[i]; f = finish[i]; c = center[i, 0]; For( j = 1, j <= ncircles & !f, j++, // circles that have stopped growing are finished If( j == i, Continue() ); td = Sqrt( Sum( (c - center[j, 0]) ^ 2 ) ); r2 = radius[j] + r; If( td < r2 + 1, f = finish[i] = If( finish[j], finish[j], HLS Color( Random Uniform(), .1 + .5 * Random Uniform(), .7 + .3 * Random Uniform() ) ); // circle i bumped circle j, chain with J color or make new color ); ); If( !f, radius[i] = r + 1; nAlive++; ); ); ); takePicture = Function( {i}, {}, g << inval; g << updatewindow; Wait( 0 ); //g[framebox( 1 )] << savepicture( dir || Right( Char( i ), 6, "0" ) || ".png", "png" ); ); For( i = 1, i <= maxcircles, i++, // find an open area to add a circle addCircle(); While( nAlive / ncircles < .05, addCircle(); nAlive++; ); growCircles(); takePicture( i ); ); For( i = i, i <= maxcircles + 500, i++, // find circles that can still grow growCircles(); takePicture( i ); );