From 5657b5f9244924b2ae5b948d415fd4724eacffb0 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 11 Dec 2023 07:43:32 +1100 Subject: [PATCH] feat(math): math.hextorgb Resolves #467. --- imports/math/shared.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/imports/math/shared.lua b/imports/math/shared.lua index 4668ca7..239107e 100644 --- a/imports/math/shared.lua +++ b/imports/math/shared.lua @@ -96,6 +96,16 @@ function math.torgba(input) return math.tovector(input, 0, 255, true) end +---Takes a hexidecimal string and returns three integers. +---@param input string +---@return integer +---@return integer +---@return integer +function math.hextorgb(input) + local r, g, b = string.match(input, '([^#]+.)(..)(..)') + return tonumber(r, 16), tonumber(g, 16), tonumber(b, 16) +end + ---Formats a number as a hexadecimal string. ---@param n number | string ---@param upper? boolean