Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw


by Grimy (Pilgrim)
on Aug 24, 2015 at 09:24 UTC ( #1139652=obfuscated: print w/replies, xml ) Need Help??

sub'r{$==rand pop}$|=print"\e[2J";r$l=`tput lines`-2,s/^$/"\e[$=;".r($ +c =`tput cols`-2).f.' Oo*... '=~s!\S\K!\e[B\b !gr/e/s/\d++\B/($a=$&-1)+( +$ ==!$a+r$a%$c?3:2)/e/s/(?<=(.)...B.)./$1/g/s/f\K./chr 32>>$=/e/s/\d+/($ +& ||$l)-1/e,select$,,$,,$,,.009*print$&?$_:"\e[f"."\e[K\n"x6while*_=r.r+ +9
EDIT: golfed it down a bit, also fixed some literal edge cases (the sprites where behaving strangely when they hit the edges of the screen).
sub'v{$==!$-+rand pop}[s/\d+/$|--?($-=$&-1)+v$-%$c?3:2:$&-print||`stty + size`- print$&?"\e[?25l\e[2J":y!Oo*.! !r/ge?s/(?<=f|(.))...B.\K./$1||chr 32>> +$=/ge.. 4E4:s/|/o*... //s//\e[B\b /g/s//\e[1;${\v$c=`tput cols`-2}fO/]while*_= +_.v-42#
The number at the beginning of the last line determines the speed (smaller = faster). The number at the end of the last line is the maximum number of sprites that can be on screen simultaneously.

Replies are listed 'Best First'.
Re: Fireworks
by ambrus (Abbot) on Aug 24, 2015 at 19:29 UTC

    Nice, works well! Though it doesn't look like fireworks for me, but more like water droplets crawling upwards on the windscreen or something. Example output:

      Yep, that’s the intended output. The “water droplets” interpretation is interesting; to me, it looks like either fireworks or spermatozoa.
Re: Fireworks
by choroba (Bishop) on Sep 07, 2015 at 15:15 UTC
    ?? without m was removed in 5.22 :-(
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      I replaced ?? with $&. This leads to a fair bit of flickering at the beginning, but works fine on v5.22.
Re: Fireworks
by davido (Archbishop) on Aug 25, 2015 at 05:11 UTC


    I only wish I didn't have to switch fonts away from Inconsolada to make it look right. But that's not the script's fault.

    Well done. I wish we saw more of these little gizmos nowadays.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://1139652]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2018-07-22 18:43 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (455 votes). Check out past polls.