From c49bf89b15ae3129a1385e73eb817b8d0d514874 Mon Sep 17 00:00:00 2001 From: Remie Richards Date: Tue, 12 May 2015 23:55:35 +0100 Subject: [PATCH] Ports /vg/ chem weighted colour averaging --- code/__HELPERS/icons.dm | 20 ++++++++ code/modules/reagents/Chemistry-Colours.dm | 55 +++++++--------------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/code/__HELPERS/icons.dm b/code/__HELPERS/icons.dm index 83e876c6dc9..37eaa81413a 100644 --- a/code/__HELPERS/icons.dm +++ b/code/__HELPERS/icons.dm @@ -618,6 +618,26 @@ world else return BlendRGB(tone, "#ffffff", (gray-tone_gray)/((255-tone_gray) || 1)) +//Used in the OLD chem colour mixing algorithm +/proc/GetColors(hex) + hex = uppertext(hex) + // No alpha set? Default to full alpha. + if(length(hex) == 7) + hex += "FF" + var/hi1 = text2ascii(hex, 2) // R + var/lo1 = text2ascii(hex, 3) // R + var/hi2 = text2ascii(hex, 4) // G + var/lo2 = text2ascii(hex, 5) // G + var/hi3 = text2ascii(hex, 6) // B + var/lo3 = text2ascii(hex, 7) // B + var/hi4 = text2ascii(hex, 8) // A + var/lo4 = text2ascii(hex, 9) // A + return list(((hi1>= 65 ? hi1-55 : hi1-48)<<4) | (lo1 >= 65 ? lo1-55 : lo1-48), + ((hi2 >= 65 ? hi2-55 : hi2-48)<<4) | (lo2 >= 65 ? lo2-55 : lo2-48), + ((hi3 >= 65 ? hi3-55 : hi3-48)<<4) | (lo3 >= 65 ? lo3-55 : lo3-48), + ((hi4 >= 65 ? hi4-55 : hi4-48)<<4) | (lo4 >= 65 ? lo4-55 : lo4-48)) + + /* Get flat icon by DarkCampainger. As it says on the tin, will return an icon with all the overlays as a single icon. Useful for when you want to manipulate an icon via the above as overlays are not normally included. diff --git a/code/modules/reagents/Chemistry-Colours.dm b/code/modules/reagents/Chemistry-Colours.dm index d2f616a9f8a..1378315276e 100644 --- a/code/modules/reagents/Chemistry-Colours.dm +++ b/code/modules/reagents/Chemistry-Colours.dm @@ -1,45 +1,24 @@ -/proc/GetColors(hex) - hex = uppertext(hex) - // No alpha set? Default to full alpha. - if(length(hex) == 7) - hex += "FF" - var/hi1 = text2ascii(hex, 2) // R - var/lo1 = text2ascii(hex, 3) // R - var/hi2 = text2ascii(hex, 4) // G - var/lo2 = text2ascii(hex, 5) // G - var/hi3 = text2ascii(hex, 6) // B - var/lo3 = text2ascii(hex, 7) // B - var/hi4 = text2ascii(hex, 8) // A - var/lo4 = text2ascii(hex, 9) // A - return list(((hi1>= 65 ? hi1-55 : hi1-48)<<4) | (lo1 >= 65 ? lo1-55 : lo1-48), - ((hi2 >= 65 ? hi2-55 : hi2-48)<<4) | (lo2 >= 65 ? lo2-55 : lo2-48), - ((hi3 >= 65 ? hi3-55 : hi3-48)<<4) | (lo3 >= 65 ? lo3-55 : lo3-48), - ((hi4 >= 65 ? hi4-55 : hi4-48)<<4) | (lo4 >= 65 ? lo4-55 : lo4-48)) /proc/mix_color_from_reagents(var/list/reagent_list) - if(!reagent_list || !reagent_list.len) return 0 + if(!istype(reagent_list)) + return - var/list/rgbcolor = list(0,0,0,0) - var/finalcolor = 0 - for(var/datum/reagent/re in reagent_list) // natural color mixing bullshit/algorithm - if(!finalcolor) - rgbcolor = GetColors(re.color) - finalcolor = re.color + var/color + var/vol_counter = 0 + var/vol_temp + + for(var/datum/reagent/R in reagent_list) + vol_temp = R.volume + vol_counter += vol_temp + + if(!color) + color = R.color + + else if (length(color) >= length(R.color)) + color = BlendRGB(color, R.color, vol_temp/vol_counter) else - var/newcolor[4] - var/prergbcolor[4] - prergbcolor = rgbcolor - newcolor = GetColors(re.color) + color = BlendRGB(R.color, color, vol_temp/vol_counter) - rgbcolor[1] = (prergbcolor[1]+newcolor[1])/2 - rgbcolor[2] = (prergbcolor[2]+newcolor[2])/2 - rgbcolor[3] = (prergbcolor[3]+newcolor[3])/2 - rgbcolor[4] = (prergbcolor[4]+newcolor[4])/2 + return color - finalcolor = rgb(rgbcolor[1], rgbcolor[2], rgbcolor[3], rgbcolor[4]) - return finalcolor -// This isn't a perfect color mixing system, the more reagents that are inside, -// the darker it gets until it becomes absolutely pitch black! I dunno, maybe -// that's pretty realistic? I don't do a whole lot of color-mixing anyway. -// If you add brighter colors to it it'll eventually get lighter, though. \ No newline at end of file