z_mirror/PipeVisualizer

git clone https://git.raiguard.me/z_mirror/PipeVisualizer

Caleb HeuerForce all colors to be value = 10c95e61

2.0
1.9 KiB91 linesraw
1--- Converts an RGB color value to HSV. Conversion formula
2--- adapted from http://en.wikipedia.org/wiki/HSV_color_space.
3--- @param input Color
4--- @return number, number, number, number
5local function rgb_to_hsv(input)
6  local r = input.r --[[@as number]]
7  local g = input.g --[[@as number]]
8  local b = input.b --[[@as number]]
9  local a = input.a --[[@as number]]
10  local max, min = math.max(r, g, b), math.min(r, g, b)
11  local h, s, v
12  v = max
13
14  local d = max - min
15  if max == 0 then
16    s = 0
17  else
18    s = d / max
19  end
20
21  if max == min then
22    h = 0 -- achromatic
23  else
24    if max == r then
25      h = (g - b) / d
26      if g < b then
27        h = h + 6
28      end
29    elseif max == g then
30      h = (b - r) / d + 2
31    elseif max == b then
32      h = (r - g) / d + 4
33    end
34    h = h / 6
35  end
36
37  return h, s, v, a
38end
39
40--- Converts an HSV color value to RGB. Conversion formula
41--- adapted from http://en.wikipedia.org/wiki/HSV_color_space.
42--- @param h number
43--- @param s number
44--- @param v number
45--- @param a number
46--- @return Color
47local function hsv_to_rgb(h, s, v, a)
48  local r, g, b
49
50  local i = math.floor(h * 6)
51  local f = h * 6 - i
52  local p = v * (1 - s)
53  local q = v * (1 - f * s)
54  local t = v * (1 - (1 - f) * s)
55
56  i = i % 6
57
58  if i == 0 then
59    r, g, b = v, t, p
60  elseif i == 1 then
61    r, g, b = q, v, p
62  elseif i == 2 then
63    r, g, b = p, v, t
64  elseif i == 3 then
65    r, g, b = p, q, v
66  elseif i == 4 then
67    r, g, b = t, p, v
68  elseif i == 5 then
69    r, g, b = v, p, q
70  end
71
72  return { r = r, g = g, b = b, a = a }
73end
74
75local function generate_fluid_colors()
76  --- @type table<string, Color>
77  local colors = {}
78  for name, fluid in pairs(game.fluid_prototypes) do
79    local h, s, v, a = rgb_to_hsv(fluid.base_color)
80    v = 1
81    colors[name] = hsv_to_rgb(h, s, v, a)
82  end
83  global.fluid_colors = colors
84end
85
86local colors = {}
87
88colors.on_init = generate_fluid_colors
89colors.on_configuration_changed = generate_fluid_colors
90
91return colors