Advertisement
swarley

Rainbow.pl [Update]

Dec 19th, 2011
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.20 KB | None | 0 0
  1.     # True Rainbow?
  2.     # True Rainow
  3.      
  4.     use strict;
  5.     use warnings;
  6.     use feature 'switch';
  7.     use Xchat ':all';
  8.      
  9.     Xchat::hook_command('rainbow', 'rainbow_test');
  10.      
  11.     my %colors = (
  12.         Red    => '04',
  13.         Orange => '07',
  14.         Yellow => '08',
  15.         Green  => '03',
  16.         Blue   => '02',
  17.         Indigo => '06',
  18.         Violet => '06');
  19.      
  20.     sub str2rainbow ($){
  21.         my $data = shift;
  22.         my @str = split(//, $data);
  23.         if (@str > 7) {
  24.             splitbow(@str);
  25.         }
  26.         else {
  27.             rainbow(@str);
  28.         }
  29.     }
  30.      
  31.     sub rainbow_test {
  32.         my $msg = $_[1][1];
  33.         Xchat::command('MSG '. Xchat::get_info('channel') . ' ' .str2rainbow($msg));
  34.     }
  35.      
  36.     sub rainbow {
  37.         my @str = @_;
  38.         my $return_str = '';
  39.         my $state = 0;
  40.         foreach my $letter (@str) {
  41.             if ($letter eq ' ') {
  42.                 $return_str .= ' ';
  43.             }
  44.             else {    
  45.                 given ($state) {
  46.                     when(0) {
  47.                         $return_str .= "\003$colors{Red}$letter";
  48.                     }
  49.                     when(1) {
  50.                         $return_str .= "\003$colors{Orange}$letter";
  51.                     }
  52.                     when(2) {
  53.                         $return_str .= "\003$colors{Yellow}$letter";
  54.                     }
  55.                     when(3) {
  56.                         $return_str .= "\003$colors{Green}$letter";
  57.                     }
  58.                     when(4) {
  59.                         $return_str .= "\003$colors{Blue}$letter";
  60.                     }
  61.                     when(5) {
  62.                         $return_str .= "\003$colors{Indigo}$letter";
  63.                     }
  64.                     when(6) {
  65.                         $return_str .= "\002\003$colors{Violet}$letter\002";
  66.                     }
  67.                 }
  68.                 ++$state;
  69.             }
  70.         }
  71.         return $return_str;
  72.     }
  73.      
  74.     sub splitbow {
  75.         my @str         = @_;
  76.         my $str_copy    = join('', @str);
  77.         $str_copy =~ s/\s+//g;
  78.         my $return_str  = '';
  79.         my @colors      = values %colors;
  80.         my $color_state = 0;
  81.         my $count_state = 0;
  82.         my $array_size  = length(join '', $str_copy);
  83.         my $per_color   = $array_size/7;
  84.         my $data        = '';
  85.         my @things      = ('','','','','','','');
  86.         foreach my $letter (@str) {
  87.             if ($count_state > $per_color && $color_state != 06) {
  88.                 ++$color_state;
  89.                 $count_state = 0;
  90.             }
  91.             if ($letter =~ m/\s/) {
  92.                 $things[$color_state] .= ' ';
  93.             }  
  94.             else {
  95.                 $things[$color_state] .= $letter;
  96.                 ++$count_state;
  97.             }
  98.             }
  99.         return rainbowformat(@things);
  100.     }
  101.  
  102.     sub rainbowformat {
  103.         my $data = '';
  104.         my $counter = 0;
  105.         my @color = ('04','07','08','03','02','06','06');
  106.         foreach my $thing (@_) {
  107.             if ($counter != 6) {
  108.                 $data .= "\003$color[$counter]$_[$counter]\003";
  109.             }
  110.             else {
  111.                 $data .= "\003$colors{Violet}\002$_[6]\002\003";
  112.             }
  113.             $counter++;
  114.         }
  115.         return $data
  116.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement