From 24cdf226b65d5c932d1af7188f9e664a34b66535 Mon Sep 17 00:00:00 2001 From: vlazed Date: Sun, 22 Dec 2024 23:51:28 -0600 Subject: [PATCH] Distance color changes + Gradient function to easily generate linearly-interpolated color gradients with NUM_GRADIENT_POINTS parameter - The color to use is automatically evaluated using the number of gradient points and the distance, allowing one to generalize beyond two gradient points - Darker colors --- lua/autorun/ragdollmover.lua | 22 +++++++++++++++++++--- lua/ragdollmover/constants.lua | 8 ++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lua/autorun/ragdollmover.lua b/lua/autorun/ragdollmover.lua index ee4bde6..3c50fe2 100644 --- a/lua/autorun/ragdollmover.lua +++ b/lua/autorun/ragdollmover.lua @@ -998,7 +998,22 @@ local COLOR_BLUE = RGM_Constants.COLOR_BLUE local COLOR_BRIGHT_YELLOW = RGM_Constants.COLOR_BRIGHT_YELLOW local OUTLINE_WIDTH = RGM_Constants.OUTLINE_WIDTH -local BONETYPE_COLORS = { { RGM_Constants.COLOR_GREEN, RGM_Constants.COLOR_DARKGREEN }, { RGM_Constants.COLOR_CYAN, RGM_Constants.COLOR_DARKCYAN }, { RGM_Constants.COLOR_YELLOW, RGM_Constants.COLOR_DARKYELLOW }, { RGM_Constants.COLOR_RED, RGM_Constants.COLOR_DARKRED } } +local function gradient(startPoint, endPoint, points) + local colors = {} + for i = 0, points-1 do + colors[i+1] = startPoint:Lerp(endPoint, i / points) + end + return colors +end + +local NUM_GRADIENT_POINTS = 2 + +local BONETYPE_COLORS = { + gradient(RGM_Constants.COLOR_GREEN, RGM_Constants.COLOR_DARKGREEN, NUM_GRADIENT_POINTS), + gradient(RGM_Constants.COLOR_CYAN, RGM_Constants.COLOR_DARKCYAN, NUM_GRADIENT_POINTS), + gradient(RGM_Constants.COLOR_YELLOW, RGM_Constants.COLOR_DARKYELLOW, NUM_GRADIENT_POINTS), + gradient(RGM_Constants.COLOR_RED, RGM_Constants.COLOR_DARKRED, NUM_GRADIENT_POINTS) +} function DrawBoneName(ent, bone, name) if not name then @@ -1118,7 +1133,6 @@ function AdvBoneSelectRender(ent, bonenodes) if not maxdist or maxdist < dist then maxdist = dist end bonedistances[i] = dist end - maxdist = maxdist - mindist local selectedBones = {} for i = 0, ent:GetBoneCount() - 1 do @@ -1142,7 +1156,9 @@ function AdvBoneSelectRender(ent, bonenodes) table.insert(selectedBones, {name, i}) else if nodesExist and bonenodes[ent][i] and bonenodes[ent][i].Type then - surface.SetDrawColor(BONETYPE_COLORS[bonenodes[ent][i].Type][( ( bonedistances[i] - mindist ) < maxdist * 0.5 ) and 1 or 2]:Unpack()) + local fraction = ( bonedistances[i] - mindist ) / (maxdist - mindist) + fraction = math.max(1, math.ceil(fraction * NUM_GRADIENT_POINTS)) + surface.SetDrawColor(BONETYPE_COLORS[bonenodes[ent][i].Type][fraction]:Unpack()) else surface.SetDrawColor(COLOR_RGMGREEN:Unpack()) end diff --git a/lua/ragdollmover/constants.lua b/lua/ragdollmover/constants.lua index 6090329..5f7475c 100644 --- a/lua/ragdollmover/constants.lua +++ b/lua/ragdollmover/constants.lua @@ -1,13 +1,13 @@ RGM_Constants = { COLOR_RED = Color(200, 0, 0, 255), - COLOR_DARKRED = Color(90, 0, 0, 255), + COLOR_DARKRED = Color(50, 0, 0, 255), COLOR_GREEN = Color(0, 200, 0, 255), - COLOR_DARKGREEN = Color(0, 90, 0, 255), + COLOR_DARKGREEN = Color(0, 50, 0, 255), COLOR_BLUE = Color(0, 0, 200, 255), COLOR_CYAN = Color(0, 200, 200, 255), - COLOR_DARKCYAN = Color(0, 90, 90, 255), + COLOR_DARKCYAN = Color(0, 50, 50, 255), COLOR_YELLOW = Color(200, 200, 0, 255), - COLOR_DARKYELLOW = Color(90, 90, 0, 255), + COLOR_DARKYELLOW = Color(50, 50, 0, 255), COLOR_BRIGHT_YELLOW = Color(255, 255, 0, 255), COLOR_WHITE = Color(255, 255, 255, 255), COLOR_BLACK = Color(0, 0, 0, 255),