Monday, July 5, 2010

Stars and stripes in perl

Perl can be made to print in color using TERM::ANSIColor. This perl program tries to generate the stars and stripes with 50 stars and 13 stripes. Although its not perfect in having larger gaps between every second row of stars, it seems to do a pretty ok job. Even the 2/5 ratio between the full and partial stripes is valid. This is the longest surviving version which has managed to complete 50 long years.

Perl does not seem to have the ability to print subscripts or superscripts while printing to the terminal atleast. The uneven spacing can probably be avoided by using subscripts or superscripts.

 #!/usr/bin/perl  
 use Term::ANSIColor qw(:constants);  
 $sixstars=" * * * * * * ";  
 $fivestars=" * * * * * ";  
 $emptystars=" ";  
 $partstripes=" \n";  
 $fullstripes=" \n";  
 print RESET;  
 print BOLD,WHITE,ON_BLUE,$sixstars;  
 print ON_RED,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$fivestars;  
 print ON_RED,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$emptystars;  
 print ON_WHITE,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$sixstars;  
 print ON_WHITE,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$fivestars;  
 print ON_RED,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$emptystars;  
 print ON_RED,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$sixstars;  
 print ON_WHITE,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$fivestars;  
 print ON_WHITE,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$emptystars;  
 print ON_RED,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$sixstars;  
 print ON_RED,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$fivestars;  
 print ON_WHITE,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$emptystars;  
 print ON_WHITE,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$sixstars;  
 print ON_RED,$partstripes,RESET;  
 print BOLD,WHITE,ON_BLUE,$emptystars;  
 print ON_RED,$partstripes,RESET;  
 for($i=0;$i<3;$i++){  
 print ON_WHITE,$fullstripes,RESET;  
 print ON_WHITE,$fullstripes,RESET;  
 print ON_RED,$fullstripes,RESET;  
 print ON_RED,$fullstripes,RESET;  
 }  

1 comment:

Anonymous said...

kam naložiti denar [url=http://www.offshorepodjetja.info]offshore podjetja[/url]