Advertisement
JoshDreamland

Attempt at by-char rainbow

Mar 17th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.59 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.         rainbow(@str);
  24.     }
  25.      
  26.     sub rainbow_test {
  27.         my $msg = $_[1][1];
  28.         Xchat::command('MSG '. Xchat::get_info('channel') . ' ' .str2rainbow($msg));
  29.     }
  30.      
  31.     sub rainbow {
  32.         my @str = @_;
  33.         my $return_str = '';
  34.         my $state = 0;
  35.         foreach my $letter (@str) {
  36.             if ($letter eq ' ') {
  37.                 $return_str .= ' ';
  38.             }
  39.             else {    
  40.                 given ($state % 7) {
  41.                     when(0) { $return_str .= "\003$colors{Red}$letter";    }
  42.                     when(1) { $return_str .= "\003$colors{Orange}$letter"; }
  43.                     when(2) { $return_str .= "\003$colors{Yellow}$letter"; }
  44.                     when(3) { $return_str .= "\003$colors{Green}$letter";  }
  45.                     when(4) { $return_str .= "\003$colors{Blue}$letter";   }
  46.                     when(5) { $return_str .= "\003$colors{Indigo}$letter"; }
  47.                     when(6) { $return_str .= "\002\003$colors{Violet}$letter\002"; }
  48.                 }
  49.                 ++$state;
  50.             }
  51.         }
  52.         return $return_str;
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement