(2 Kb)
Updated: 09-27-13 09:28 AM
Pictures
File Info
 Updated: 09-27-13 09:28 AM Created: 09-26-13 01:15 PM Downloads: 792 Favorites: 2 MD5:

# ColorSmudge

Version: 50400.02
by: zork [More]

Info:

Addon takes two RGB colors and and on a given percentage morphs from colorA to colorB using HSV returning a new intermediate RGB color.
Function:
Lua Code:
1. local CS = CreateFrame("ColorSelect")
2.
3. --GetSmudgeColorRGB function
4. --arg1: color table in RGB {r=0,g=0,b=0}
5. --arg2: color table in RGB {r=1,g=1,b=1}
6. --arg3: percentage 0-1
7. function CS:GetSmudgeColorRGB(colorA,colorB,percentage)
8.   self:SetColorRGB(colorA.r, colorA.g, colorA.b)
9.   colorA.h, colorA.s, colorA.v = self:GetColorHSV()
10.   self:SetColorRGB(colorB.r, colorB.g, colorB.b)
11.   colorB.h, colorB.s, colorB.v = self:GetColorHSV()
12.   local colorC = {}
13.   --check if the angle between the two H values is > 180
14.   if abs(colorA.h-colorB.h) > 180 then
15.     local angle = (360-abs(colorA.h-colorB.h))*percentage
16.     if colorA.h < colorB.h then
17.       colorC.h = floor(colorA.h-angle)
18.       if colorC.h < 0 then
19.         colorC.h = 360+colorC.h
20.       end
21.     else
22.       colorC.h = floor(colorA.h+angle)
23.       if colorC.h > 360 then
24.         colorC.h = colorC.h-360
25.       end
26.     end
27.   else
28.     colorC.h = floor(colorA.h-(colorA.h-colorB.h)*percentage)
29.   end
30.   colorC.s = colorA.s-(colorA.s-colorB.s)*percentage
31.   colorC.v = colorA.v-(colorA.v-colorB.v)*percentage
32.   self:SetColorHSV(colorC.h, colorC.s, colorC.v)
33.   colorC.r, colorC.g, colorC.b = self:GetColorRGB()
34.   return colorC
35. end
36.
37. --GetSmudgeColorRGB function call
38. local color = CS:GetSmudgeColorRGB({r=1,g=0,b=0}, {r=0,g=1,b=0}, 0.5)
GIT
https://github.com/zorker/rothui/tre....0/ColorSmudge

50400.02
- color smudge will now use the shortest path between two colors

50400.01
- initial release
Optional Files (0)

Archived Files (1)
 File Name Version Size Author Date 50400.01 2kB zork 09-26-13 01:15 PM

 Comment Options
09-27-13, 02:10 AM
zork
A Pyroguard Emberseer

Forum posts: 1680
--upodated-----

Fixed the drycode.

Lua Code:
1. if abs(self.colorA.h-self.colorB.h) > 180 then
3.       --calculate the 360° breakpoint
4.       if self.colorA.h < self.colorB.h then
6.         if self.colorC.h < 0 then
7.           self.colorC.h = 360+self.colorC.h
8.         end
9.       else
11.         if self.colorC.h > 360 then
12.           self.colorC.h = self.colorC.h-360
13.         end
14.       end
15.     else
16.       self.colorC.h = floor(self.colorA.h-(self.colorA.h-self.colorB.h)*self.percentage/100)
17.     end
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

 "I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
Last edited by zork : 09-28-13 at 05:27 AM.

 09-27-13, 04:30 PM suicidalkatt A Rage Talon Dragon Guard   Forum posts: 326 File comments: 1448 Uploads: 62 Does perfectly! Thanks for your work! __________________ -->> The Ultimate Shaman UI - Official Thread <<--
10-01-13, 08:38 AM
zork
A Pyroguard Emberseer

Forum posts: 1680
Some functions
Lua Code:
1. --color lib
2. local CS = CreateFrame("ColorSelect")
3.
4. --ConvertColorRgbToHsv
5. function ConvertColorRgbToHsv(color)
6.   CS:SetColorRGB(color.r, color.g, color.b)
7.   local h,s,v = CS:GetColorHSV()
8.   return {h=h,s=s,v=v}
9. end
10.
11. --ConvertColorHsvToRgb
12. function ConvertColorHsvToRgb(color)
13.   CS:SetColorHSV(color.h, color.s, color.v)
14.   local r,g,b = CS:GetColorRGB()
15.   return {r=r,g=g,b=b}
16. end
17.
18. --CalculateNewColor
19. function CalculateNewColor(colorA,colorB,percentage)
20.   local colorC = {}
21.   --check if the angle between the two H values is > 180
22.   if abs(colorA.h-colorB.h) > 180 then
23.     local angle = (360-abs(colorA.h-colorB.h))*percentage
24.     if colorA.h < colorB.h then
25.       colorC.h = floor(colorA.h-angle)
26.       if colorC.h < 0 then
27.         colorC.h = 360+colorC.h
28.       end
29.     else
30.       colorC.h = floor(colorA.h+angle)
31.       if colorC.h > 360 then
32.         colorC.h = colorC.h-360
33.       end
34.     end
35.   else
36.     colorC.h = floor(colorA.h-(colorA.h-colorB.h)*percentage)
37.   end
38.   colorC.s = colorA.s-(colorA.s-colorB.s)*percentage
39.   colorC.v = colorA.v-(colorA.v-colorB.v)*percentage
40.   return colorC
41. end
42.
43. --GetSmudgeColor
44. function GetSmudgeColor(colorA,colorB,percentage)
45.   if colorA.r then
46.     return ConvertColorHsvToRgb(CalculateNewColor(ConvertColorRgbToHsv(colorA),ConvertColorRgbToHsv(colorB),percentage))
47.   elseif colorA.h then
48.     return CalculateNewColor(colorA,colorB,percentage)
49.   end
50.   return nil
51. end
52.
53. --function call
54. local color = GetSmudgeColor({r=1,g=0,b=0}, {r=0,g=1,b=0}, 0.5)
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

 "I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
Last edited by zork : 10-22-13 at 02:04 AM.

 04-06-17, 05:51 PM chrislue A Defias Bandit Forum posts: 2 File comments: 26 Uploads: 0 I doubt anyone would see this, but what's the bar texture used in the picture?

Category Jump: