Changed color mixing to use weighted average instead of addition. Should help against values reaching FF too fast.

Adjusted color mixing helper to use inbuilt procs.
This commit is contained in:
Chinsky
2014-06-18 23:45:25 +04:00
parent 9e3ad09b8c
commit ceecd7abc9
2 changed files with 9 additions and 30 deletions

View File

@@ -224,12 +224,6 @@ turf/proc/update_lumcount(amount, _lcolor, removing = 0)
var/blended
if (_lcolor)
if (l_color && _lcolor && l_color != _lcolor && !removing) // Blend colors.
var/redblend = min((GetRedPart(l_color)) + (GetRedPart(_lcolor)), 255)
var/greenblend = min((GetGreenPart(l_color)) + (GetGreenPart(_lcolor)), 255)
var/blueblend = min((GetBluePart(l_color)) + (GetBluePart(_lcolor)), 255)
blended = "#[add_zero2(num2hex(redblend), 2)][add_zero2(num2hex(greenblend),2)][add_zero2(num2hex(blueblend),2)]"
if (removing)
colors.Remove(_lcolor) // Remove the color that's leaving us from our list.
@@ -237,23 +231,7 @@ turf/proc/update_lumcount(amount, _lcolor, removing = 0)
l_color = null // All our color is gone, no color for us.
else if (colors && colors.len > 1)
var/maxdepth = 3 // Will blend 3 colors, anymore than that and it looks bad or we will get lag on every tile update.
var/currentblended
for (var/i = 0, ++i <= colors.len)
if (i > maxdepth)
//world << "Maxdepth reached, breaking loop."
break
if (!currentblended)
//world << "First iteration, currentblended = [colors[i]]."
currentblended = colors[i] // Start with the first of the remaining colors.
continue
var/redblend = min((GetRedPart(currentblended)) + (GetRedPart(colors[i])), 255)
var/greenblend = min((GetGreenPart(currentblended)) + (GetGreenPart(colors[i])), 255)
var/blueblend = min((GetBluePart(currentblended)) + (GetBluePart(colors[i])), 255)
currentblended = "#[add_zero2(num2hex(redblend), 2)][add_zero2(num2hex(greenblend), 2)][add_zero2(num2hex(blueblend), 2)]"
//world << "Finished [i] [currentblended]."
var/currentblended = MixColors(colors.Copy(1,maxdepth+1))
if (currentblended)
//world << "Ended up with [currentblended]"
@@ -264,6 +242,8 @@ turf/proc/update_lumcount(amount, _lcolor, removing = 0)
l_color = colors[colors.len]
else // we added a color.
colors.Add(_lcolor) // Add the base color to the list.
if (l_color && _lcolor && l_color != _lcolor) // Blend colors.
blended = MixColors(list(l_color,_lcolor))
if (blended)
l_color = blended // If we had a blended color, this is what we get otherwise.

View File

@@ -34,7 +34,7 @@
var/blue = mixOneColor(weight,bluecolor)
//assemble all the pieces
var/finalcolor = "#[red][green][blue]"
var/finalcolor = rgb(red, green, blue)
return finalcolor
/proc/mixOneColor(var/list/weight, var/list/color)
@@ -58,10 +58,9 @@
mixedcolor = round(mixedcolor)
//until someone writes a formal proof for this algorithm, let's keep this in
if(mixedcolor<0x00 || mixedcolor>0xFF)
return 0
// if(mixedcolor<0x00 || mixedcolor>0xFF)
// return 0
//that's not the kind of operation we are running here, nerd
mixedcolor=min(max(mixedcolor,0),255)
var/finalcolor = num2hex(mixedcolor)
while(length(finalcolor)<2)
finalcolor = text("0[]",finalcolor) //Takes care of leading zeroes
return finalcolor
return mixedcolor