AppleScript名:calcColorDomainLib |
— Created 2018-01-08 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property NSColor : a reference to current application’s NSColor set {rCol, gCol, bCol} to choose color set cName to retColorDomainName(rCol, gCol, bCol, 65535) of me set cValue to retColorDomainValue(rCol, gCol, bCol, 65535) of me return {cName, cValue} on retColorDomainName(rCol as integer, gCol as integer, bCol as integer, aColorMax) set aCol to makeNSColorFromRGBAval(rCol, gCol, bCol, aColorMax, aColorMax) of me return retColorDomainNameFronNSColor(aCol) of me end retColorDomainName on retColorDomainNameFronNSColor(aCol) set hueVal to aCol’s hueComponent() set satVal to aCol’s saturationComponent() set brightVal to aCol’s brightnessComponent() if satVal ≤ 0.01 then set satVal to 0.0 set colName to "" if satVal = 0.0 then if brightVal ≤ 0.2 then set colName to "black" else if (brightVal > 0.95) then set colName to "white" else set colName to "gray" end if else if hueVal ≤ (15.0 / 360) or hueVal ≥ (330 / 360) then set colName to "red" else if hueVal ≤ (45.0 / 360) then set colName to "orange" else if hueVal < (70.0 / 360) then set colName to "yellow" else if hueVal < (150.0 / 360) then set colName to "green" else if hueVal < (190.0 / 360) then set colName to "light blue" –cyan else if (hueVal < 250.0 / 360.0) then set colName to "blue" else if (hueVal < 290.0 / 360.0) then set colName to "purple" else set colName to "pink" –magenta end if end if return colName end retColorDomainNameFronNSColor on retColorDomainValue(rCol as integer, gCol as integer, bCol as integer, aColorMax) set aCol to makeNSColorFromRGBAval(rCol, gCol, bCol, aColorMax, aColorMax) of me return retColorDomainValueFromNSColor(aCol) of me end retColorDomainValue on retColorDomainValueFromNSColor(aCol) set hueVal to aCol’s hueComponent() set satVal to aCol’s saturationComponent() set brightVal to aCol’s brightnessComponent() if satVal ≤ 0.01 then set satVal to 0.0 if satVal = 0.0 then if brightVal ≤ 0.2 then set colVal to {0, 0, 0} –Black else if (brightVal > 0.95) then set colVal to {65535, 65535, 65535} –White else set colVal to {32768, 32768, 32768} –Gray end if else if hueVal ≤ (15.0 / 360) or hueVal ≥ (330 / 360) then set colVal to {65535, 0, 0} –red else if hueVal ≤ (45.0 / 360) then set colVal to {65535, 32768, 0} –orange else if hueVal < (70.0 / 360) then set colVal to {65533, 63639, 2654} –yellow else if hueVal < (150.0 / 360) then set colVal to {4626, 35488, 17789} –green else if hueVal < (190.0 / 360) then set colVal to {0, 60802, 65535} –cyan, light blue else if (hueVal < 250.0 / 360.0) then set colVal to {0, 0, 65535} –blue else if (hueVal < 290.0 / 360.0) then set colVal to {32768, 0, 32768} –purple else set colVal to {65535, 0, 65535} –magenta, pink end if end if return colVal end retColorDomainValueFromNSColor on makeNSColorFromRGBAval(redValue as integer, greenValue as integer, blueValue as integer, alphaValue as integer, aMaxVal as integer) set aRedCocoa to (redValue / aMaxVal) as real set aGreenCocoa to (greenValue / aMaxVal) as real set aBlueCocoa to (blueValue / aMaxVal) as real set aAlphaCocoa to (alphaValue / aMaxVal) as real set aColor to NSColor’s colorWithCalibratedRed:aRedCocoa green:aGreenCocoa blue:aBlueCocoa alpha:aAlphaCocoa return aColor end makeNSColorFromRGBAval |
More from my site
(Visited 82 times, 1 visits today)
Keynoteでタイトルがマスターに入っていなかった場合に矯正 v2 - AppleScript Hole says:
[…] このままだと、色データが{0,0,1}になったぐらいで検出できなくなってしまいますが、Color Domain処理を組み合わせることで「だいたい黒」「黒っぽい色」といった判定が行えるため、組み […]