For those in a holiday mood.

Generates a random Christmas tree out of a few ASCII characters. Takes an optional width commandline argument.

Merry Christmas!

#!/usr/bin/perl sub symbol { my $r = rand; return '|' if $r < .07; return 'o' if $r < .15; '*'; } my $width = shift || 30; for my $cnt (1..$width/2) { print "\n", ' ' x ($width/2 - $cnt); print symbol for 1..2*$cnt; } print "\n", ' ' x ($width/2 - 2) . "_||_\n\n\n";

Replies are listed 'Best First'.
Re: ASCII Christmas tree generator
by belg4mit (Prior) on Dec 24, 2003 at 19:16 UTC
    A golfed version for a sig... the major improvement IMHO being the symbol function.
    sub c{rand>.07&&return'*';rand>.5?'o':'|';}my$w=shift()/2||15;for my$i +(1..$w) {print"\n",' 'x($w-$i);print c for 1..2*$i;}print"\n",' 'x($w-2),"_||_ +\n\n\n";
    I couldn't come up with a decent star to top the tree...

    --
    I'm not belgian but I play one on TV.

Re: ASCII Christmas tree generator
by LanX (Saint) on Nov 06, 2015 at 00:09 UTC