Re:A single line of Basic sends readers into a labyrinth
by guiambros on Saturday December 01, 2012 @10:41AM
(#4857902)
> ...not as elegant as the BASIC version
Beautiful statement. So much unintentional irony, and at the same time so very true in this context.
Re:A single line of Basic sends readers into a labyrinth
by billysilly on Saturday December 01, 2012 @06:48AM
(#4857418)
I 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');
Re:A single line of Basic sends readers into a labyrinth
by vmind on Saturday December 01, 2012 @12:53PM
(#4858371)
(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))
I shortened it a bit:
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.