From 5dd5e5070433ef3508ff57864b37b2c19e032302 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Thu, 21 Apr 2022 11:10:32 +0200 Subject: [PATCH] Colorspec: Use hex numbers to improve readability --- minetest/colorspec.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/minetest/colorspec.lua b/minetest/colorspec.lua index b5656c8..166015c 100644 --- a/minetest/colorspec.lua +++ b/minetest/colorspec.lua @@ -210,7 +210,7 @@ function colorspec.from_string(string) if not number then return end - alpha = tonumber(alpha_text, 16) + alpha = tonumber(alpha_text, 0x10) end end if number then @@ -220,7 +220,7 @@ function colorspec.from_string(string) if not hex_text then return end - local len, num = hex_text:len(), tonumber(hex_text, 16) + local len, num = hex_text:len(), tonumber(hex_text, 0x10) if len == 8 then return colorspec.from_number_rgba(num) end @@ -229,17 +229,17 @@ function colorspec.from_string(string) end if len == 4 then return colorspec.from_table{ - a = (num % 16) * 17, - b = (floor(num / 16) % 16) * 17, - g = (floor(num / (16 ^ 2)) % 16) * 17, - r = (floor(num / (16 ^ 3)) % 16) * 17 + a = (num % 0x10) * 0x11, + b = (floor(num / 0x10) % 0x10) * 0x11, + g = (floor(num / (0x100)) % 0x10) * 0x11, + r = (floor(num / (0x1000)) % 0x10) * 0x11 } end if len == 3 then return colorspec.from_table{ - b = (num % 16) * 17, - g = (floor(num / 16) % 16) * 17, - r = (floor(num / (16 ^ 2)) % 16) * 17 + b = (num % 0x10) * 0x11, + g = (floor(num / 0x10) % 0x10) * 0x11, + r = (floor(num / (0x100)) % 0x10) * 0x11 } end end