Thread Tools Display Modes
Prev Previous Post   Next Post Next
09-10-16, 03:00 AM   #1
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Gradient Color Help

Hi, i'm trying to gradient color my FPS/MS when its dropping but its not working that great!

Its either i only get it to either green or red..

Lua Code:
  1. A.ColorGradient = function(a, b, ...)
  2.     local Percent
  3.  
  4.     if b == 0 then
  5.         Percent = 0
  6.     else
  7.         Percent = a / b
  8.     end
  9.  
  10.     if Percent >= 1 then
  11.         local R, G, B = select(select("#", ...) - 2, ...)
  12.  
  13.         return R, G, B
  14.     elseif Percent <= 0 then
  15.         local R, G, B = ...
  16.  
  17.         return R, G, B
  18.     end
  19.  
  20.     local Num = (select("#", ...) / 3)
  21.     local Segment, RelPercent = modf(Percent * (Num - 1))
  22.     local R1, G1, B1, R2, G2, B2 = select((Segment * 3) + 1, ...)
  23.  
  24.     return R1 + (R2 - R1) * RelPercent, G1 + (G2 - G1) * RelPercent, B1 + (B2 - B1) * RelPercent
  25. end

Lua Code:
  1. A.RGBToHex = function(R, G, B)
  2.     R = R <= 1 and R >= 0 and R or 0
  3.     G = G <= 1 and G >= 0 and G or 0
  4.     B = B <= 1 and B >= 0 and B or 0
  5.  
  6.     return format("|cff%02x%02x%02x", R * 255, G * 255, B * 255)
  7. end

Lua Code:
  1. local AStatsFrame = CreateFrame("Frame", nil, UIParent)
  2. AStatsFrame:SetSize(160, 50)
  3. AStatsFrame:SetPoint("BOTTOMLEFT", UIParent, -35, -15.5)
  4.  
  5. local AStatsText = AStatsFrame:CreateFontString(nil, "OVERLAY")
  6. AStatsText:SetPoint("CENTER", AStatsFrame, 0, 0)
  7. AStatsText:SetFont(C.Media.Font2, 12, "THINOUTLINE")
  8. AStatsText:SetShadowOffset(1, -1)
  9. AStatsText:SetShadowColor(0,0,0)
  10. AStatsText:SetTextColor(A.ClassColor.r, A.ClassColor.g, A.ClassColor.b)
  11.  
  12. local FPS = GetFramerate()
  13. local MS = select(3, GetNetStats())
  14.  
  15. local FR, FG, FB = A.ColorGradient(FPS, 15, 100, .8, 0, .8, .8, 0, .8, 0, 0)
  16. local MR, MG, MB = A.ColorGradient(MS, 1000, 100, .8, 0, .8, .8, 0, .8, 0, 0)
  17.  
  18. local ColorFPS = A.RGBToHex(FR, FG, FB)
  19. local ColorMS = A.RGBToHex(MR, MG, MB)
  20.  
  21. local Int = 0
  22.  
  23. AStatsFrame:SetScript("OnUpdate", function(self, elapsed)
  24.     Int = Int - elapsed
  25.     if Int <= 0 then
  26.  
  27.         local FPS = GetFramerate()
  28.         local MS = select(3, GetNetStats())
  29.        
  30.         --AStatsText:SetText(string.format("%s%d|r fps %s%d|r ms", ColorFPS(FPS), FPS, ColorLag(MS), MS))
  31.         AStatsText:SetText(string.format("%s%d|r fps %s%d|r ms", ColorFPS, FPS, ColorMS, MS))
  32.        
  33.         Int = 1
  34.     end
  35. end)
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Gradient Color Help


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off