mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-20 03:25:49 +01:00
@@ -405,22 +405,6 @@ proc/isInSight(var/atom/A, var/atom/B)
|
||||
GetBluePart(hexa)
|
||||
)
|
||||
|
||||
/proc/MixColors(const/list/colors)
|
||||
var/list/reds = list()
|
||||
var/list/blues = list()
|
||||
var/list/greens = list()
|
||||
var/list/weights = list()
|
||||
|
||||
for (var/i = 0, ++i <= colors.len)
|
||||
reds.Add(GetRedPart(colors[i]))
|
||||
blues.Add(GetBluePart(colors[i]))
|
||||
greens.Add(GetGreenPart(colors[i]))
|
||||
weights.Add(1)
|
||||
|
||||
var/r = mixOneColor(weights, reds)
|
||||
var/g = mixOneColor(weights, greens)
|
||||
var/b = mixOneColor(weights, blues)
|
||||
return rgb(r,g,b)
|
||||
|
||||
/proc/alone_in_area(var/area/the_area, var/mob/must_be_alone, var/check_type = /mob/living/carbon)
|
||||
var/area/our_area = get_area_master(the_area)
|
||||
|
||||
@@ -1,66 +1,29 @@
|
||||
/proc/mix_color_from_reagents(var/list/reagent_list)
|
||||
if(!reagent_list || !length(reagent_list))
|
||||
return 0
|
||||
/*
|
||||
* Returns:
|
||||
* #RRGGBB(AA) on success, null on failure
|
||||
*/
|
||||
/proc/mix_color_from_reagents(const/list/reagent_list)
|
||||
if(!istype(reagent_list))
|
||||
return
|
||||
|
||||
var/contents = length(reagent_list)
|
||||
var/list/weight = new /list(contents)
|
||||
var/list/redcolor = new /list(contents)
|
||||
var/list/greencolor = new /list(contents)
|
||||
var/list/bluecolor = new /list(contents)
|
||||
var/i
|
||||
var/color
|
||||
var/reagent_color
|
||||
var/vol_counter = 0
|
||||
var/vol_temp
|
||||
// see libs/IconProcs/IconProcs.dm
|
||||
for(var/datum/reagent/reagent in reagent_list)
|
||||
if(reagent.id == "blood" && reagent.data["blood_colour"])
|
||||
reagent_color = reagent.data["blood_colour"]
|
||||
else
|
||||
reagent_color = reagent.color
|
||||
|
||||
//fill the list of weights
|
||||
for(i=1; i<=contents; i++)
|
||||
var/datum/reagent/re = reagent_list[i]
|
||||
var/reagentweight = re.volume
|
||||
if(istype(re, /datum/reagent/paint))
|
||||
reagentweight *= 20 //Paint colours a mixture twenty times as much
|
||||
weight[i] = reagentweight
|
||||
vol_temp = reagent.volume
|
||||
vol_counter += vol_temp
|
||||
|
||||
if(isnull(color))
|
||||
color = reagent.color
|
||||
else if(length(color) >= length(reagent_color))
|
||||
color = BlendRGB(color, reagent_color, vol_temp/vol_counter)
|
||||
else
|
||||
color = BlendRGB(reagent_color, color, vol_temp/vol_counter)
|
||||
|
||||
//fill the lists of colours
|
||||
for(i=1; i<=contents; i++)
|
||||
var/datum/reagent/re = reagent_list[i]
|
||||
var/hue = re.color
|
||||
if(length(hue) != 7)
|
||||
return 0
|
||||
redcolor[i]=hex2num(copytext(hue,2,4))
|
||||
greencolor[i]=hex2num(copytext(hue,4,6))
|
||||
bluecolor[i]=hex2num(copytext(hue,6,8))
|
||||
|
||||
//mix all the colors
|
||||
var/red = mixOneColor(weight,redcolor)
|
||||
var/green = mixOneColor(weight,greencolor)
|
||||
var/blue = mixOneColor(weight,bluecolor)
|
||||
|
||||
//assemble all the pieces
|
||||
var/finalcolor = rgb(red, green, blue)
|
||||
return finalcolor
|
||||
|
||||
/proc/mixOneColor(var/list/weight, var/list/color)
|
||||
if (!weight || !color || length(weight)!=length(color))
|
||||
return 0
|
||||
|
||||
var/contents = length(weight)
|
||||
var/i
|
||||
|
||||
//normalize weights
|
||||
var/listsum = 0
|
||||
for(i=1; i<=contents; i++)
|
||||
listsum += weight[i]
|
||||
for(i=1; i<=contents; i++)
|
||||
weight[i] /= listsum
|
||||
|
||||
//mix them
|
||||
var/mixedcolor = 0
|
||||
for(i=1; i<=contents; i++)
|
||||
mixedcolor += weight[i]*color[i]
|
||||
mixedcolor = round(mixedcolor)
|
||||
|
||||
//until someone writes a formal proof for this algorithm, let's keep this in
|
||||
// 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)
|
||||
|
||||
return mixedcolor
|
||||
|
||||
Reference in New Issue
Block a user