source: branches/locker-dev/noc/ng/cgi-bin/testcolor.cgi @ 1326

Last change on this file since 1326 was 42, checked in by presbrey, 18 years ago
scripts.mit.edu NOC graphing
File size: 1.4 KB
Line 
1#!/usr/bin/perl
2
3# File:    $Id: testcolor.cgi,v 1.2 2005/10/08 05:55:08 sauber Exp $
4# Author:  (c) Soren Dossing, 2005
5# License: OSI Artistic License
6#          http://www.opensource.org/licenses/artistic-license.php
7
8use strict;
9use CGI qw/:standard/;
10
11# Suggest some commonly used keywords
12my $w = param('words') ? join ' ', param('words') : 'response rta pctfree';
13
14# Start each page with an input field
15print <<EOF;
16Content-type: text/html
17
18<html><body>
19<form>
20Type some space seperated nagiosgraph line names here:<br>
21<input name=words size=80 value="$w">
22<input type=submit>
23</form><br>
24EOF
25
26# Render a table of colors of all schemes for each keyword
27if ( param('words') ) {
28  print "<table cellpadding=0><tr><td></td>";
29  print "<th>$_</th>" for 1..8;
30  print "</tr>\n";
31  for my $w ( split /\s+/, param('words') ) {
32    print "<tr><td>$w</td>";
33    for my $c ( 1..8 ) {
34      my $h = hashcolor($w, $c);
35      print "<td><table bgcolor=#000000><tr><td bgcolor=#$h>&nbsp;</td></tr></table></td>";
36    }
37    print "</tr>\n";
38  }
39  print "</table>\n";
40}
41
42# End of page
43print "</body></html>\n";
44
45# Calculate a color for a keyword
46#
47sub hashcolor {
48  my$c=$_[1];map{$c=1+(51*$c+ord)%(216)}split//,$_[0];
49  my($i,$n,$m,@h);@h=(51*int$c/36,51*int$c/6%6,51*($c%6));
50  for$i(0..2){$m=$i if$h[$i]<$h[$m];$n=$i if$h[$i]>$h[$n]}
51  $h[$m]=102if$h[$m]>102;$h[$n]=153if$h[$n]<153;
52  $c=sprintf"%06X",$h[2]+$h[1]*256+$h[0]*16**4;
53  return $c;
54}
55
Note: See TracBrowser for help on using the repository browser.