#!/usr/bin/perl -w use strict; if( $#ARGV != 0 ) { die "$0 \n"; } my $line_count = $ARGV[0]; my $pi = atan2(0, -1); my @buffer = (); for(my $i = 0; $i < 20; $i++) { push @buffer, (("X" x 79) . "\n"); } my $char = 0; my $zone = 0; for(; $line_count > 0; $line_count--) { # Generate extra rows when buffered rows fall below some threshold. # Note that the newly appended rows are not sufficient to hold # generated stars, so every new star may overlap a bit with # previously generated star. if( $#buffer < 50 ) { # Fill buffer with extra rows for(my $i = 0; $i < 20; $i++) { push @buffer, (("X" x 79) . "\n"); } # Generate star my $cx = rand(40) - 20 + ($zone ? 20 : 79 - 20); my $size0 = 1 + rand(2); my $size1 = 12 - $size0 + rand(8); my $phase = rand(2 * $pi); for(my $ta = 0; $ta < 10 * $pi; $ta += 0.1) { my $r = $size0 + $size1 + $size1 * 0.5 * sin($ta + $phase); for(my $tr = 0; $tr < $r; $tr += 0.1) { my $x = $cx + $tr * cos($ta / 5); my $y = $#buffer - 20 + $tr * sin($ta / 5) * 0.5; $y = int($y + 0.5); $x = int($x + 0.5); if( $x >= 0 && $x < length($buffer[$y]) ) { substr($buffer[int($y + 0.5)], int($x + 0.5), 1) = ' '; } } } $zone ^= 1; } # Output text following template my $template = shift @buffer; foreach my $c (unpack 'C*', $template) { $c = chr($c); if( $c =~ /\s/s ) { print $c; } else { print chr($char + ord('a')); $char = ($char + 1) % 26; } } }