def mix(color1, color2, weight = Number.new(50))
assert_type color1, :Color
assert_type color2, :Color
assert_type weight, :Number
unless (0..100).include?(weight.value)
raise ArgumentError.new("Weight #{weight} must be between 0% and 100%")
end
# This algorithm factors in both the user-provided weight
# and the difference between the alpha values of the two colors
# to decide how to perform the weighted average of the two RGB values.
#
# It works by first normalizing both parameters to be within [-1, 1],
# where 1 indicates "only use color1", -1 indicates "only use color 0",
# and all values in between indicated a proportionately weighted average.
#
# Once we have the normalized variables w and a,
# we apply the formula (w + a)/(1 + w*a)
# to get the combined weight (in [-1, 1]) of color1.
# This formula has two especially nice properties:
#
# * When either w or a are -1 or 1, the combined weight is also that number
# (cases where w * a == -1 are undefined, and handled as a special case).
#
# * When a is 0, the combined weight is w, and vice versa
#
# Finally, the weight of color1 is renormalized to be within [0, 1]
# and the weight of color2 is given by 1 minus the weight of color1.
p = (weight.value/100.0).to_f
w = p*2 - 1
a = color1.alpha - color2.alpha
w1 = (((w * a == -1) ? w : (w + a)/(1 + w*a)) + 1)/2.0
w2 = 1 - w1
rgb = color1.rgb.zip(color2.rgb).map {|v1, v2| v1*w1 + v2*w2}
alpha = color1.alpha*p + color2.alpha*(1-p)
Color.new(rgb + [alpha])
end
Exactly. It's less trivial than you've been making it out to be.
That is just your opinion, though. You're welcome to have that opinion. Don't assume it's more than an opinion.
I always had a base. You just baselessly assumed that my assumption was baseless. Also, that's twice you've misspelled my name now.
This is the big difference with remapping colors client-side (as opposed to parsing and assigning color), and having customizable color server-side. If it wasn't clear that we were doing type mapping, not just blanket color reassignment, it's not surprising that people thought the feature was dumb.
I started out reading this thread with the assumption that the discussion pertained to mapping colors to types. That seemed to get dismissed after the arguments about quantity of types. That's when I switched to assuming the discussion pertained to mapping colors to colors. And yes, it did seem exceedingly dumb. Still, even when we go back to colors to types, my same basic issue holds. If we use my room titles example where color is differentiated by plane of existence, and may also contain other color representing additional information - we end up requiring a non-trivial amount of logic and seven (unless we're only allowing selection between preset color themes) different user configuration settings just for room titles. That's a lot for one type, and I'm not even sure I'd consider it an edge case. HK already touched on this some, and so did you - it gets complex quickly.
On another topic, I think the biggest issue in this thread is the misleading nature of the word "full", as it has been applied to color customization. When I see the word "full", I interpret it as giving the ability for players to fully customize every instance of color in the entire game UI. Obviously, that will produce an unwieldy UI just for configuring the colors, unless we're talking about a very simple game and/or one with sparse color. It seems that the scope of the color customization we're discussing is slowly being dialed back now. So, where exactly do we draw the line between what IS being discussed and something simple like 'color <off/minimum/standard/maximum>'?
Something is core or essential the moment you decide it is. I typically decide that about most things, as I'm always looking for ways to more deeply integrate new features. My weather system is something I used to consider core and essential - it was one of the first major systems written for my game (early 2002). However, the weather code hasn't been touched since then; so, it is now outdated and has a much smaller impact on the game world than I would like. It must be rewritten (in 2-3 years when I reach that point on the list)!!