Show HN: Print chr$(205.5+rnd(1)) goto 10

42 points by atum47 ↗ HN
JavaScript implementation of the famous `10 print chr$(205.5+rnd(1)) goto 10` one line of BASIC code.

data:text/html,<script>a=()=>{document.write(Math.random()<0.5?'\u2571':'\u2572');document.body.style.cssText="margin:0;padding:0;font-family:monospace;word-break:break-word;font-size:3em;letter-spacing:0;font-stretch:ultra-expanded"};update=()=>{a();window.requestAnimationFrame(update)};update()</script>

Copy and paste the above "link" in your browser.

16 comments

[ 3.4 ms ] story [ 46.7 ms ] thread
Bravo. Just ran this, seeing the JIT kick in was a trip.

Data URIs: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_...

Chrome seems to compile before it runs it. Only Firefox takes some lines before it runs it as fast as Chrome. Now I wonder why it takes so long to do the JIT? I always thought that JIT compiles with every execution...
As I understand it there's a "baseline" compilation, then after n calls it's specialized according to the types/values seen.
The result looks like this:

    ╱╲╱╱╱╲╲╱╲╲╲╱╲╱╲╱╲╲╲╲╱╲╱╲╲╱╲╱╱╲╱╲╱╱╲╱╲╲╲╲╲╱╲╱╲╲╲╲╲╲╲╲╱╲╱╱╱╱╲╲╱╱╲╱╲╲╱╱╱╱╲╱╱╲╲╱╲╱╲╲╱╱╲╱╱╲╱╱╲╱╲╲╲╲╲╱╱╱╱╲╲╲╱╱╲╱╲╲╱╲╱╲╲╲╱╱╱╲╱╱╱╲╱╲╱╱╲╲╲╲╲╲╲╲╱╱╲╲╲╱╲╲╱╱╲╲╲╱╲╲╲╲╱╲╱╲╲╲╲╱╲╱╱╲╱╱╱╲╲╲╲
    ╲╱╲╱╲╲╲╱╱╲╱╱╲╱╲╲╱╱╲╱╲╲╱╲╲╱╲╲╲╲╲╲╱╲╱╱╲╱╱╱╱╱╱╲╲╱╱╲╱╱╲╱╱╲╲╲╲╱╱╲╱╱╱╱╱╲╲╱╲╱╲╲╲╱╱╱╱╲╱╲╱╲╱╱╱╱╲╲╲╲╱╱╱╱╱╱╱╲╲╱╲╲╱╱╱╱╱╲╱╲╱╱╱╱╲╲╱╱╱╱╱╱╲╱╲╲╱╲╲╱╱╲╱╲╱╲╱╲╲╱╲╱╱╲╱╲╱╲╲╲╲╲╱╲╲╱╱╲╱╱╲╱╲╱╲╱╲╱╱╲╱
    ╱╲╱╱╱╲╲╲╲╱╲╲╱╱╱╱╲╲╲╲╲╲╱╱╲╲╲╲╱╲╲╱╲╱╱╲╱╲╲╲╱╱╱╲╱╱╲╱╲╱╲╱╲╱╲╲╲╱╱╲╱╱╱╱╱╲╱╱╱╲╲╲╱╱╲╱╲╱╲╱╱╲╱╱╱╲╱╱╱╲╲╱╲╱╱╱╲╱╱╲╱╱╲╱╲╱╱╱╱╲╲╲╲╱╲╱╲╲╱╲╱╱╱╲╱╲╱╲╲╲╲╲╱╲╱╱╲╱╲╱╲╲╲╲╱╲╱╱╱╲╲╱╱╲╱╱╲╲╲╲╲╲╲╲╱╱╱╱╲╲╱
    ╲╱╲╱╲╲╲╱╲╲╱╲╱╱╲╱╱╲╲╱╱╲╱╱╲╱╱╲╲╱╲╱╱╲╲╱╱╱╱╱╲╲╱╲╲╱╱╱╲╲╲╲╱╱╲╲╱╲╲╱╱╱╱╱╲╱╱╱╲╱╱╱╱╱╲╱╲╲╱╲╱╲╱╲╱╱╱╲╱╲╲╲╱╱╱╲╲╱╱╱╱╲╲╲╱╲╲╲╲╱╲╱╱╱╱╲╱╲╱╱╱╲╱╱╲╱╱╲╱╲╱╱╱╱╲╱╱╲╱╲╱╱╲╱╲╱╱╲╱╲╲╲╱╲╲╲╱╲╱╱╱╲╱╱╲╲╱╲╱╲╲
    ╲╲╲╱╱╱╲╲╱╱╱╲╱╲╱╱╱╲╲╱╱╲╲╲╱╱╲╱╱╲╲╲╲╱╲╱╱╲╲╲╲╲╲╱╱╱╱╱╱╲╱╲╲╱╱╲╱╲╲╱╱╲╲╱╱╱╲╱╱╲╱╱╲╱╱╲╱╲╱╱╱╱╲╱╱╱╲╱╱╱╲╱╱╲╱╱╲╱╲╲╱╲╲╲╱╲╲╲╲╱╱╲╱╱╱╲╱╲╲╲╱╲╲╲╱╲╱╱╲╱╲╲╱╱╱╱╱╲╲╱╲╱╲╱╲╱╱╲╱╲╲╲╲╲╱╱╲╱╱╱╱╲╲╲╲╱╲╲╱╲╱
    ╲╱╲╲╱╲╲╲╱╱╲╱╲╲╱╱╲╱╲╱╲╲╱╲╲╲╱╲╱╲╱╲╲╲╲╲╱╲╱╲╱╱╱╱╱╱╲╲╱╲╲╱╲╱╱╲╱╱╲╱╱╱╱╲╱╲╱╱╱╲╱╲╲╲╲╱╲╲╱╲╲╱╲╱╱╱╱╲╱╲╲╲╱╱╲╲╱╱╲╲╱╲╲╱╲╱╲╱╱╱╲╲╱╲╱╱╲╲╲╲╱╲╱╱╱╲╲╱╱╱╱╱╲╲╱╱╱╱╱╱╱╱╱╱╲╱╲╲╱╱╲╲╱╱╲╲╱╱╲╱╲╲╱╱╱╱╲╱╲╲╱
In which browsers? This doesn't seem to work for me in Chrome, but maybe it's just me. Works in Firefox and Safari.

Edit: Nevermind, I tried again and it did begin to run before the tab closed abruptly. Tried again in an incognito window and it worked, and it also worked in a regular Chrome window with only one tab. Tried to run it in a second tab in that same window and the tab instantly closed again. Anyone know why this might be the case?

Second edit: While it doesn't run in regular Chrome windows with multiple tabs, it does run in Incognito windows with multiple tabs. I don't think I have the expertise to dig further though.

I'm using breve these days and it works. It's chromium based
It works but doesn't scroll automatically like others :) Still a neat idea! I had also written one in Z80 Assembly in 14-bytes for Amstrad CPC computers: https://github.com/ssg/mazecpc
Here it is with scrolling:

data:text/html,<script>a=()=>{document.write(Math.random()<0.5?'\u2571':'\u2572');document.body.style.cssText="margin:0;padding:0;font-family:monospace;word-break:break-word;font-size:3em;letter-spacing:0;font-stretch:ultra-expanded"};update=()=>{a();window.requestAnimationFrame(update);window.scroll(0,window.scrollMaxY)};update()</script>

Add 'line-height:1em;' to make it look a bit cooler.
Uh, why is it so slow?
The loop is scheduled using window.requestAnimationFrame, which follows the browser's refresh rate.
It also detect hardware to decide if it's going to run at 60 or 120 fps. Also don't animate if the tab is not visible

    data:text/html,<script>a=()=>{document.write('\u{1F600}');document.body.style.cssText="margin:0;padding:0;font-family:monospace;word-break:break-word;font-size:3em;letter-spacing:0;font-stretch:ultra-expanded"};update=()=>{a();window.requestAnimationFrame(update)};update()</script>

or maybe change 1F600 to 1F44D :)
WoW really cool effect! Love this kind of works!