Live data from Hacker News

A single line of Basic sends readers into a labyrinth

slate.com

81–90 of 91 posts

Re: A single line of Basic sends readers into a labyrinth

#81

Earlier quoted context omitted.

I tried to like it. I bumped up the font size to 36 points. I slowed down the loop to .01 seconds. Unfortunately, it isn't remotely the same. The C64 had magic. I miss my old C64.

Try this: http://www.secretgeometry.com/apps/cathode/ Lots of fun. Use it to make old stuff like this feel more authentic, or just run your builds in it and tell your housemates you're haxxing teh gibson. TBH though the reason it doesn't feel the same is ultimately because you're not the person you were 20-30 years ago, whoever that was. Nothing to do with the code or its execution environment.

While it was far better (and thanks for the pointer to Cathode!), I figured out what the problems are. First (and probably most important), the lines being output don't touch each other, so there are horizontal gaps across the entire screen. Second, the glyphs are much thinner, reducing the feeling of "wall".

Re: A single line of Basic sends readers into a labyrinth

#82
post #62

Earlier quoted context omitted.

Hmm.. 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 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…

I won't claim this is elegant, but here's the same thing in one line: for(i=1;i " : (Math.random()>0.5) ? '\u2571' : '\u2572');

(function draw(i){ return function () { document.write(i%30==0 ? '
' : 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 ? '
' : Math.random()>0.5 ? '\u2571':'\u2572'); draw(i+1); }, 100) }(1))

Re: A single line of Basic sends readers into a labyrinth

#83
post #10

A version that works in bash: yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash Source and credit: http://stackoverflow.com/a/13612327

PowerShell for those on Windows: for (;;) { write-host -n (get-random ╱,╲) } Obviously this requires a font supporting those characters. MS Mincho seems to serve well: http://www.microsoft.com/typography/fonts/font.aspx?FMID=206

If you don't want to install a font, you can use slashes. Works pretty well.

    for (;;) { write-host -n (get-random /,\) }
It's kind of nice with _ and | too :

    for (;;) { write-host -n (get-random '_','|') }

Re: A single line of Basic sends readers into a labyrinth

#86
post #59
post #10

A version that works in bash: yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash Source and credit: http://stackoverflow.com/a/13612327

The one-line shell command python version ended up being surprisingly painful: echo "# -*- coding: utf-8 -*-\\nfrom random import choice\\nwhile(True):\\n print(choice(\"╱╲\"), end='')" | python3 or python3 -c 'exec("from random import choice\nwhile(True):\n print(choice(\"╱╲\"), end='"''"')")' (Oh, the fun of deeply nested quote escaping!) The exec / echo thing being required since we need multiple lines, because wh…

I did it with

    python3 -c "`echo -e 'import time\nwhile True:\n print(u"\u2571\u2572"[int(time.time() * 100)%2],end="")\n time.sleep(0.001)'`"
The neat thing about it is that the randomness comes from the inexactness of time.sleep

Re: A single line of Basic sends readers into a labyrinth

#87
post #59
post #10

A version that works in bash: yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash Source and credit: http://stackoverflow.com/a/13612327

The one-line shell command python version ended up being surprisingly painful: echo "# -*- coding: utf-8 -*-\\nfrom random import choice\\nwhile(True):\\n print(choice(\"╱╲\"), end='')" | python3 or python3 -c 'exec("from random import choice\nwhile(True):\n print(choice(\"╱╲\"), end='"''"')")' (Oh, the fun of deeply nested quote escaping!) The exec / echo thing being required since we need multiple lines, because wh…

You can write it like this:

    python -c "while 1:import sys,random;sys.stdout.write(random.choice('\/'))"
and it's shorter too !

Re: A single line of Basic sends readers into a labyrinth

#88

It may be somewhat interesting to analyze the properties of randomly-generated labyrinths of this type. For instance, some spaces are clearly enclosed. i.e., there is a finite border outside which you cannot escape. Some paths seem to run on for a very long time. Are all paths enclosed? If so, given a random point on a randomly generated maze, what is the average area of an enclosure?

Mathematicians have given this some thought. The relevant keyword seems to be "Truchet tilings", though there's a curved variation that's more widely known. Here's a very accessible overview with some lovely generalizations of this pattern: http://mypages.iit.edu/~krawczyk/rjkisama11.pdf

Re: A single line of Basic sends readers into a labyrinth

#89

Another fun example of a computer generating mezmerizingly complex art from simple code is that as a kid, I wrote a Langton's Ant implementation in QBASIC on a DOS machine (don't remember the version). IIRC this was using Graphics Mode 1 (320 x 200 pixel framebuffer), and I used PSET and PRESET to draw white and black pixels. This so far sounds ordinary but: The cool thing was that I forgot to write the bounds check…

I had the same bug (no pun intended), but in JavaScript. It does produce some interesting effects after making a few laps. http://chengsun.github.com/walk.html I still am a "kid", and it amuses me that I'm making the same stuff on modern platforms that have already been done on DOS machines by kids like me.

Awesome!! Glad you were able to reproduce the effect! :D

Re: A single line of Basic sends readers into a labyrinth

#90
post #10

A version that works in bash: yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash Source and credit: http://stackoverflow.com/a/13612327

Interactive JavaScript version: http://js.do/samples/labyrinth

Here's a JavaScript version without the linebreaks (it uses zero-width spaces instead): http://tinkerbin.com/uEvgxZ6g

JS: for(i=0;iCSS: body {line-height: 1}

Post reply on HN