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:
A.ColorGradient = function(a, b, ...)
local Percent
if b == 0 then
Percent = 0
else
Percent = a / b
end
if Percent >= 1 then
local R, G, B = select(select("#", ...) - 2, ...)
return R, G, B
elseif Percent <= 0 then
local R, G, B = ...
return R, G, B
end
local Num = (select("#", ...) / 3)
local Segment, RelPercent = modf(Percent * (Num - 1))
local R1, G1, B1, R2, G2, B2 = select((Segment * 3) + 1, ...)
return R1 + (R2 - R1) * RelPercent, G1 + (G2 - G1) * RelPercent, B1 + (B2 - B1) * RelPercent
end
Lua Code:
A.RGBToHex = function(R, G, B)
R = R <= 1 and R >= 0 and R or 0
G = G <= 1 and G >= 0 and G or 0
B = B <= 1 and B >= 0 and B or 0
return format("|cff%02x%02x%02x", R * 255, G * 255, B * 255)
end
Lua Code:
local AStatsFrame = CreateFrame("Frame", nil, UIParent)
AStatsFrame:SetSize(160, 50)
AStatsFrame:SetPoint("BOTTOMLEFT", UIParent, -35, -15.5)
local AStatsText = AStatsFrame:CreateFontString(nil, "OVERLAY")
AStatsText:SetPoint("CENTER", AStatsFrame, 0, 0)
AStatsText:SetFont(C.Media.Font2, 12, "THINOUTLINE")
AStatsText:SetShadowOffset(1, -1)
AStatsText:SetShadowColor(0,0,0)
AStatsText:SetTextColor(A.ClassColor.r, A.ClassColor.g, A.ClassColor.b)
local FPS = GetFramerate()
local MS = select(3, GetNetStats())
local FR, FG, FB = A.ColorGradient(FPS, 15, 100, .8, 0, .8, .8, 0, .8, 0, 0)
local MR, MG, MB = A.ColorGradient(MS, 1000, 100, .8, 0, .8, .8, 0, .8, 0, 0)
local ColorFPS = A.RGBToHex(FR, FG, FB)
local ColorMS = A.RGBToHex(MR, MG, MB)
local Int = 0
AStatsFrame:SetScript("OnUpdate", function(self, elapsed)
Int = Int - elapsed
if Int <= 0 then
local FPS = GetFramerate()
local MS = select(3, GetNetStats())
--AStatsText:SetText(string.format("%s%d|r fps %s%d|r ms", ColorFPS(FPS), FPS, ColorLag(MS), MS))
AStatsText:SetText(string.format("%s%d|r fps %s%d|r ms", ColorFPS, FPS, ColorMS, MS))
Int = 1
end
end)