#!/bin/sh # MetaCard 2.4 stack # The following is not ASCII text, # so now would be a good time to q out of more exec mc $0 "$@" Colors2 ifunction RGBtoHSV rgb put (item 1 of rgb / 255) into r put (item 2 of rgb /255) into g put (item 3 of rgb / 255) into b put max(r,g,b) into theMax put theMax into v put min(r,g,b) into theMin put theMax - theMin into delta if delta = 0 then -- grey multiply v by 255 -- convert to percent return "0,0," & round(v) else if theMax <> 0 then put delta / theMax into s else -- r & g & b all = 0 put 0 into s put 0 into h -- don't really know but this will do return "0,0,0" end if if r = theMax then put (g - b) / delta into h -- between yellow & magenta else if g = theMax then put 2 + (b - r) / delta into h -- between cyan & yellow else put 4 + (r - g) / delta into h -- between magenta & cyan end if multiply h by 60 -- convert to degrees if h < 0 then add 360 to h multiply s by 100 -- convert to percent multiply v by 100 -- convert to percent put round(h) & comma & round(s) & comma & round(v) into hsv return hsv end RGBtoHSV -- r,g,b values are from 0 to 1 -- h = [0,360], s = [0,1], v = [0,1] -- if s == 0, then h = -1 (undefined) function HSVtoRGB hsv put item 1 of hsv into h put (item 2 of hsv / 100) into s put (item 3 of hsv / 100) into v if s = 0 then -- grey put v * 100 into temp return temp & comma & temp & comma & temp end if divide h by 60 put trunc(h) into i put h - i into f -- fractional part of h put v * (1 - s) into p put v * (1 - s * f) into q put v * (1 - s * (1 - f)) into t switch i case 0 put v into r put t into g put p into b break case 1 put q into r put v into g put p into b break case 2 put p into r put v into g put t into b break case 3 put p into r put q into g put v into b break case 4 put t into r put p into g put v into b break case 5 put v into r put p into g put q into b break end switch put round(r * 255) & comma & round(g * 255) & comma & round(b * 255) into rgb return rgb end HSVtoRGB function reverseRGB oldCol put item 1 of oldCol into r put item 2 of oldCol into g put item 3 of oldCol into b put (255 - r) & comma into newRGB put (255 - g) & comma after newRGB put (255 - b) after newRGB return newRGB end reverseRGB ffdg}Colors UArial UArial WArialWArial cREVGeneralscriptChecksumXJdJ7&aKL bookmarks handlerListRGBtoHSV HSVtoRGB reverseRGB tempScript prevHandlerscriptSelectionchar 798 to 797script

function RGBtoHSV rgb

put (item 1 of rgb / 255) into r

put (item 2 of rgb /255) into g

put (item 3 of rgb / 255) into b

put max(r,g,b) into theMax

put theMax into v

put min(r,g,b) into theMin

put theMax - theMin into delta

if delta = 0 then

-- grey

multiply v by 255 -- convert to percent

return "0,0," & round(v)

else if theMax <> 0 then

put delta / theMax into s

else

-- r & g & b all = 0

put 0 into s

put 0 into h -- don't really know but this will do

return "0,0,0"

end if

if r = theMax then

put (g - b) / delta into h -- between yellow & magenta

else if g = theMax then

put 2 + (b - r) / delta into h -- between cyan & yellow

else

put 4 + (r - g) / delta into h -- between magenta & cyan

end if

multiply h by 60 -- convert to degrees

if h < 0 then add 360 to h

multiply s by 100 -- convert to percent

multiply v by 100 -- convert to percent

put round(h) & comma & round(s) & comma & round(v) into hsv

return hsv

end RGBtoHSV

-- r,g,b values are from 0 to 1

-- h = [0,360], s = [0,1], v = [0,1]

-- if s == 0, then h = -1 (undefined)

function HSVtoRGB hsv

put item 1 of hsv into h

put (item 2 of hsv / 100) into s

put (item 3 of hsv / 100) into v

if s = 0 then

-- grey

put v * 100 into temp

return temp & comma & temp & comma & temp

end if

divide h by 60

put trunc(h) into i

put h - i into f -- fractional part of h

put v * (1 - s) into p

put v * (1 - s * f) into q

put v * (1 - s * (1 - f)) into t

switch i

case 0

put v into r

put t into g

put p into b

break

case 1

put q into r

put v into g

put p into b

break

case 2

put p into r

put v into g

put t into b

break

case 3

put p into r

put q into g

put v into b

break

case 4

put t into r

put p into g

put v into b

break

case 5

put v into r

put p into g

put q into b

break

end switch

put round(r * 255) & comma & round(g * 255) & comma & round(b * 255) into rgb

return rgb

end HSVtoRGB

function reverseRGB oldCol

put item 1 of oldCol into r

put item 2 of oldCol into g

put item 3 of oldCol into b

put (255 - r) & comma into newRGB

put (255 - g) & comma after newRGB

put (255 - b) after newRGB

return newRGB

end reverseRGB

 @}TestExTon mouseUp answer color with the backColor of this stack put it into startingColor put RGBtoHSV(startingColor) into hsvColor put HSVtoRGB(hsvColor) into rgbColor set the backColor of this stack to rgbColor put "Start: " & startingColor & cr & "HSV: " & hsvColor & cr & \ "RGB: " & rgbColor into fld "Data" end mouseUp .d cREVGeneralscriptChecksumUnic+ revUniqueID 1044224019312 bookmarks handlerListmouseUp tempScript prevHandlermouseUpscriptSelectionchar 327 to 326script

on mouseUp

answer color with the backColor of this stack

put it into startingColor

put RGBtoHSV(startingColor) into hsvColor

put HSVtoRGB(hsvColor) into rgbColor

set the backColor of this stack to rgbColor

put "Start: " & startingColor & cr & "HSV: " & hsvColor & cr & \

"RGB: " & rgbColor into fld "Data"

end mouseUp

Data)`86 cREVGeneral revUniqueID 1047107478485  Start: 255,255,102 HSV: 60,60,100 RGB: 255,255,102