4 ms·
Interactive JavaScript version: http://js.do/samples/labyrinth http://js.do/samples/labyrinth
by rsiqueira 14y ago
Interactive JavaScript version:
http://js.do/samples/labyrinth http://js.do/samples/labyrinth
- itry 14y agoHmm.. thats not a oneliner. Which is what makes the Basic version interesting in the first place. Also it differs in that it does not run continously. I shortened it a bit: http://js.do/code/154 http://js.do/code/154 Still not as elegant as the Basic version. This is one of the big downsides of how javascript is implemented in the browsers these days. There is no simple way to redraw the screen. You have to turn your whole program into a state machine and work with timouts just to display something.
- billysilly 14y agoI won't claim this is elegant, but here's the same thing in one line: for(i=1;i<300;i++) document.write(i % 30 == 0 ? "<br>" : (Math.random()>0.5) ? '\u2571' : '\u2572');
- vmind 14y ago(function draw(i){ return function () { document.write(i%30==0 ? '<br>' : Math.random()>0.5?'\u2571':'\u2572'); setTimeout(draw(i+1), 100) } }(1)()) A throttled run-forever version. edit, slightly neater: (function draw(i){ setTimeout(function (){ document.write(i%30==0 ? '<br>' : Math.random()>0.5 ? '\u2571':'\u2572'); draw(i+1); }, 100) }(1))
- guiambros 14y ago> ...not as elegant as the BASIC version Beautiful statement. So much unintentional irony, and at the same time so very true in this context.
- kelseyhigham 14y agoHere's a JavaScript version without the linebreaks (it uses zero-width spaces instead): http://tinkerbin.com/uEvgxZ6g http://tinkerbin.com/uEvgxZ6g JS: for(i=0;i<1000;i++) document.write(['\u2571\u200B', '\u2572\u200B'][(Math.floor((Math.random()*2)))]) CSS: body {line-height: 1}