This one-liner draws a patchy pattern using a simple game-of-life-like cellular automaton. You can see the pattern evolving.
If you use a larger terminal window, the pattern is larger as well, but the program gets slower. In general, this program isn't written with speed in mind, it could be made much faster.
perl -we '($H,$W)=`stty size`=~/^(\d+) (\d+)/?($1-1,$2):(24,80);$w=$W+
+20;@a = map { rand() < 1/3 } 0 .. ($H+20)*$w; print "\e[H\e[J"; for (
+0 .. 30) { print "\e[H"; for (0 .. 1) { @a = map { $c = $_; $s = 0; $
+s += $a[($c + $_) % @a] for -$w-1, -$w, -$w+1, -1, 1, $w-1, $w, $w+1;
+ $s < 3 } 0 .. @a - 1; } for $y (10 .. $H + 9) { for $x (10 .. $W + 9
+) { print $a[$y*$w + $x] ? "#" : " "; } print "\n"; } }'
Update: you can try changing the parameter 1/3.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.