!752 static BWImage bw; static Thread producer; static Reproducing rp; !include #1004556 // class Reproducing static int luaMaxSteps = 1000*1000; p { rp = new Reproducing; rendererMaker = func(S s) { if (startsWith(s, "lua ")) ret luaRenderer(dropPrefix("lua ", s)); null; // fallback to default (unstructure) }; bw = rp.bw = loadBWImage("#1004576"); rp.imageSurfaceToUpdateWithBest = showImage(bw.getBufferedImage()); rp.startProduction = r { produce() }; // Note: This doesn't terminate as it keeps looking for better // solutions. It does write the shortest100.txt file in the mean // time which is your real output. rp.findShortest100_openEnd(); } static void produce() { cancelThread(producer); producer = new Thread(r { // STRATEGY! rp.push(fullGrab(bw)); int w = 1; while licensed { rp.push(new RandomSolid().reproduce(bw)); S best = rp.bestDesc(); if (best != null) rp.push(varyFloat(best)); if (w < bw.getWidth()) rp.push(hrepeat(bw, w++)); } }, "Producer"); producer.start(); } static Renderer luaRenderer(final S code) { ret new Renderer { public BWImage render(int w, int h) { BWImage img = new BWImage(w, h); Sandbox sandbox = makeSandbox(img); luaMaxSteps(luaMaxSteps); quickLua(sandbox, code); ret img; } }; } static Sandbox makeSandbox(final BWImage img) { Sandbox s = luaSandbox(); s.setOuter("w", Lua.value(img.getWidth())); s.setOuter("h", Lua.value(img.getHeight())); s.setInner("set", new ThreeArgFunction() { public LuaValue call(LuaValue x, LuaValue y, LuaValue theByte) { img.setByte(x.toint(), y.toint(), (byte) theByte.toint()); ret Lua.NIL; } }); ret s; }