| 1 | ############################################################################## | ||
| 2 | # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. # | ||
| 3 | # # | ||
| 4 | # This program is free software; you can redistribute it and/or # | ||
| 5 | # modify it under the terms of the GNU General Public License # | ||
| 6 | # as published by the Free Software Foundation; either version 2 # | ||
| 7 | # of the License, or (at your option) any later version. # | ||
| 8 | # # | ||
| 9 | # This program is distributed in the hope that it will be useful, # | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
| 12 | # GNU General Public License for more details. # | ||
| 13 | # # | ||
| 14 | # You should have received a copy of the GNU General Public License # | ||
| 15 | # along with this program; if not, write to the Free Software # | ||
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.# | ||
| 17 | # # | ||
| 18 | # Jon Howell can be contacted at: # | ||
| 19 | # 6211 Sudikoff Lab, Dartmouth College # | ||
| 20 | # Hanover, NH 03755-3510 # | ||
| 21 | # jonh@cs.dartmouth.edu # | ||
| 22 | # # | ||
| 23 | # An electronic copy of the GPL is available at: # | ||
| 24 | # http://www.gnu.org/copyleft/gpl.html # | ||
| 25 | # # | ||
| 26 | ############################################################################## | ||
| 27 | |||
| 28 | use strict; | ||
| 29 | |||
| 30 | package FAQ::OMatic::ColorPicker; | ||
| 31 | |||
| 32 | sub findRGB { | ||
| 33 | my $horizFrac = shift; # fraction of distance along horizontal of image | ||
| 34 | my $vertFrac = shift; | ||
| 35 | |||
| 36 | my $f16 = 1/6; | ||
| 37 | my $f26 = 2/6; | ||
| 38 | my $f36 = 3/6; | ||
| 39 | my $f46 = 4/6; | ||
| 40 | my $f56 = 5/6; | ||
| 41 | my $f66 = 1; | ||
| 42 | |||
| 43 | my ($hue, $red, $green, $blue); | ||
| 44 | |||
| 45 | $hue = $horizFrac; | ||
| 46 | if ($hue<$f16) { | ||
| 47 | $red = 1; | ||
| 48 | $green = $hue*6; | ||
| 49 | $blue = 0; | ||
| 50 | } elsif ($hue<$f26) { | ||
| 51 | $red = ($f26-$hue)*6; | ||
| 52 | $green = 1; | ||
| 53 | $blue = 0; | ||
| 54 | } elsif ($hue<$f36) { | ||
| 55 | $red = 0; | ||
| 56 | $green = 1; | ||
| 57 | $blue = 1-($f36-$hue)*6; | ||
| 58 | } elsif ($hue<$f46) { | ||
| 59 | $red = 0; | ||
| 60 | $green = ($f46-$hue)*6; | ||
| 61 | $blue = 1; | ||
| 62 | } elsif ($hue<$f56) { | ||
| 63 | $red = 1-($f56-$hue)*6; | ||
| 64 | $green = 0; | ||
| 65 | $blue = 1; | ||
| 66 | } else { # $hue<$f66 | ||
| 67 | $red = 1; | ||
| 68 | $green = 0; | ||
| 69 | $blue = ($f66-$hue)*6; | ||
| 70 | } | ||
| 71 | if ($vertFrac<0.5) { # blend toward white | ||
| 72 | my $trans = 2*$vertFrac; # at middle, $trans = 1 | ||
| 73 | $red = $trans*$red + (1-$trans)*1; | ||
| 74 | $green = $trans*$green + (1-$trans)*1; | ||
| 75 | $blue = $trans*$blue + (1-$trans)*1; | ||
| 76 | } else { | ||
| 77 | my $trans = 2*(1-$vertFrac); # at middle, $trans = 1 | ||
| 78 | $red = $trans*$red + 0; | ||
| 79 | $green = $trans*$green + 0; | ||
| 80 | $blue = $trans*$blue + 0; | ||
| 81 | } | ||
| 82 | |||
| 83 | return ($red,$green,$blue); | ||
| 84 | } | ||
| 85 | |||
| 86 | 1; |