4 ms·
import sys, random while True: sys.stdout.write(random.choice([u'\u2571', u'\u2572'])) sys.stdout.flush() They're called box drawing characters,
by lima 9y ago
import sys, random
while True:
sys.stdout.write(random.choice([u'\u2571', u'\u2572']))
sys.stdout.flush()
They're called box drawing characters, it's how ncurses applications draw their GUI.
https://en.wikipedia.org/wiki/Box-drawing_character https://en.wikipedia.org/wiki/Box-drawing_character
- zaf 9y ago# Without unicode or pygame (using Python3) import sys, random while True : print( random.choice( [ chr( 92 ) , chr( 47 ) ] ) , end = "" ) sys.stdout.flush( )
- icc97 9y agoThis one doesn't look correct in the terminal though as the characters don't join up (parent): ╱╱╱╲╲╲╲╲╲╱╲╲╲╱╱╱╲╱╱╱╲╲╲ ╱╱╲╲╲╲╲╲╲╲╱╱╲╲╲╱╲╲╱╱╲╲╲ vs (yours) \\\/\\\//\//\\///\\\\////\ /\////\\\//\\\/\/\/\\\\/ Also in the terminal there isn't the space between the lines for the parent either (that's just HN formatting), but there is a space when using \ or /
- zaf 9y agoThat's because of HN formatting.
- icc97 9y agoIt's because u'\u2571' is a different character from chr(92)
- rubenbe 9y agoThe C64 font is (almost?) square, this also contributes to the nice effect.
- rothron 9y agoIt's square as it's 8x8 pixels, but the pixels themselves are not. There's a difference in aspect ratio between PAL and NTSC variants, and because the C64 was usually connected to a CRT, pretty much all bets are off.
- Ao7bei3s 9y agoimport random while True: print(random.choice("╱╲"), end="") How's that for readability?
- junke 9y agoWhy flush?
- lima 9y agoI initially put a sleep in, it's unnecessary in this case.
- fermuch 9y agoIn some terminals, python buffers the output until it has enough and then dumps it to the console. IIRC it is like this because the console can be pretty slow, so by buffering you can do more calculations instead of always waiting for the console.
- int_19h 9y agoIt should always flush at the end of the line though, no?