Building Scripts

Add Gradient Color to Descriptions

This script will take a text file with the desired description and 5 colors and print out the colorized description to the command line. If the description is longer than 7 lines, split it into multiple inputs so the gradient properly loops. You only need to pass the single letter color codes, NOT the &+ - that is provided in the script.

This script was designed in Linux using perl. It should work under other operating systems with a valid installation of perl, but it has not been tested. Please contact Koira on MT if you have any questions.

gradcolor.pl
#!/usr/bin/perl
# script to add gradient color using Medieval Times MUD ansi codes
# can color with 3 colors or 5, up to 7 lines of description
# written by Koira on May 22nd, 2012
 
my $usage = "Usage: ./gradcolor.pl file color1 color2 color3 color4 color5\n
If you wish to only use 3 colors, simply pass the same color2 and color3 twice.\n";
die($usage) if (@ARGV != 6);
 
# open files
open(my $desc, "<", "$ARGV[0]") or die "Could not open description file.\n";
 
# set needed vars/array
my @chars;
my $n = 0;
my $col1 = $ARGV[1];
my $col2 = $ARGV[2];
my $col3 = $ARGV[3];
my $col4 = $ARGV[4];
my $col5 = $ARGV[5];
 
# loop through each line of the file
while (my $line = <$desc>){
  chomp($line);
  @chars = split(//,$line);
 
# group 1
  splice(@chars,$n+1,0,"&+$col2");
  splice(@chars,$n+4,0,"&+$col3");
  splice(@chars,$n+7,0,"&+$col2");
  splice(@chars,$n+10,0,"&+$col1");
 
# group 2
  splice(@chars,$n+24,0,"&+$col4");
  splice(@chars,$n+27,0,"&+$col5");
  splice(@chars,$n+30,0,"&+$col4");
  splice(@chars,$n+33,0,"&+$col1");
 
# group 3
  splice(@chars,$n+47,0,"&+$col2");
  splice(@chars,$n+50,0,"&+$col3");
  splice(@chars,$n+53,0,"&+$col2");
  splice(@chars,$n+56,0,"&+$col1");
 
# group 4
  splice(@chars,$n+70,0,"&+$col4");
  splice(@chars,$n+73,0,"&+$col5");
  splice(@chars,$n+76,0,"&+$col4");
  splice(@chars,$n+79,0,"&+$col1");
 
# join together the line and increment
  my $final = join("",@chars);
  print "&+", $col1, $final, "&N\n";
  $n = $n+2;
}
 
close($desc);

Add Rainbow Gradient to Lines

This script will take a file with a single line and cycle through the rainbow on each character.

grainbow.pl
#!/usr/bin/perl
# script to rainbow-ize using Medieval Times MUD ansi codes
# written by Koira on May 23nd, 2012
 
my $usage = "Usage: ./rainbow.pl file\n
Make sure file only has one line\n";
die($usage) if (@ARGV != 1);
 
 
# open file and format input
open(my $desc,"<","$ARGV[0]") or die "Could not open description file.\n";
my $line = <$desc>;
chomp($line);
 
# setup array
my @chars;
@chars = split(//,$line);
my $length = @chars;
my $newline;
my $n=0;
 
# color elements in array
while($n < $length){
  $newline .= "&+R$chars[$n]";
  $newline .= "&+r$chars[$n+1]";
  $newline .= "&+y$chars[$n+2]";
  $newline .= "&+Y$chars[$n+3]";
  $newline .= "&+G$chars[$n+4]";
  $newline .= "&+g$chars[$n+5]";
  $newline .= "&+b$chars[$n+6]";
  $newline .= "&+B$chars[$n+7]";
  $newline .= "&+C$chars[$n+8]";
  $newline .= "&+c$chars[$n+9]";
  $newline .= "&+m$chars[$n+10]";
  $newline .= "&+M$chars[$n+11]";
  $n = $n + 12;
}
 
# print result and close
print $newline, "&N\n";
close($desc);
scripts/building.txt · Last modified: 2012/05/24 03:54 by koira
Firefox 3