diff --git a/code/__HELPERS/colors.dm b/code/__HELPERS/colors.dm index c50ab79e0c4..760704cc560 100644 --- a/code/__HELPERS/colors.dm +++ b/code/__HELPERS/colors.dm @@ -1,8 +1,7 @@ /// Given a color in the format of "#RRGGBB", will return if the color /// is dark. -/proc/is_color_dark(color, threshold = 0.25) - var/list/rgb = hex2rgb(color) - var/list/hsl = rgb2hsl(rgb[1], rgb[2], rgb[3]) +/proc/is_color_dark(color, threshold = 25) + var/hsl = rgb2num(color, COLORSPACE_HSL) return hsl[3] < threshold /// Given a 3 character color (no hash), converts it into #RRGGBB (with hash) diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm index e9f65ab369a..2162eca1b80 100644 --- a/code/__HELPERS/type2type.dm +++ b/code/__HELPERS/type2type.dm @@ -152,71 +152,6 @@ GLOBAL_LIST_INIT(modulo_angle_to_dir, list(NORTH,NORTHEAST,EAST,SOUTHEAST,SOUTH, . = "NONE" return . -//colour formats -/proc/rgb2hsl(red, green, blue) - red /= 255;green /= 255;blue /= 255; - var/max = max(red,green,blue) - var/min = min(red,green,blue) - var/range = max-min - - var/hue=0;var/saturation=0;var/lightness=0; - lightness = (max + min)/2 - if(range != 0) - if(lightness < 0.5) - saturation = range/(max+min) - else - saturation = range/(2-max-min) - - var/dred = ((max-red)/(6*max)) + 0.5 - var/dgreen = ((max-green)/(6*max)) + 0.5 - var/dblue = ((max-blue)/(6*max)) + 0.5 - - if(max==red) - hue = dblue - dgreen - else if(max==green) - hue = dred - dblue + (1/3) - else - hue = dgreen - dred + (2/3) - if(hue < 0) - hue++ - else if(hue > 1) - hue-- - - return list(hue, saturation, lightness) - -/proc/hsl2rgb(hue, saturation, lightness) - var/red;var/green;var/blue; - if(saturation == 0) - red = lightness * 255 - green = red - blue = red - else - var/a;var/b; - if(lightness < 0.5) - b = lightness*(1+saturation) - else - b = (lightness+saturation) - (saturation*lightness) - a = 2*lightness - b - - red = round(255 * hue2rgb(a, b, hue+(1/3))) - green = round(255 * hue2rgb(a, b, hue)) - blue = round(255 * hue2rgb(a, b, hue-(1/3))) - - return list(red, green, blue) - -/proc/hue2rgb(a, b, hue) - if(hue < 0) - hue++ - else if(hue > 1) - hue-- - if(6*hue < 1) - return (a+(b-a)*6*hue) - if(2*hue < 1) - return b - if(3*hue < 2) - return (a+(b-a)*((2/3)-hue)*6) - return a - /// For finding out what body parts a body zone covers, the inverse of the below basically /proc/zone2body_parts_covered(def_zone) switch(def_zone) @@ -340,58 +275,6 @@ GLOBAL_LIST_INIT(modulo_angle_to_dir, list(NORTH,NORTHEAST,EAST,SOUTHEAST,SOUTH, else . = max(0, min(255, 138.5177312231 * log(temp - 10) - 305.0447927307)) - -/proc/color2hex(color) //web colors - if(!color) - return "#000000" - - switch(color) - if("white") - return "#FFFFFF" - if("black") - return "#000000" - if("gray") - return "#808080" - if("brown") - return "#A52A2A" - if("red") - return "#FF0000" - if("darkred") - return "#8B0000" - if("crimson") - return "#DC143C" - if("orange") - return "#FFA500" - if("yellow") - return "#FFFF00" - if("green") - return "#008000" - if("lime") - return "#00FF00" - if("darkgreen") - return "#006400" - if("cyan") - return "#00FFFF" - if("blue") - return "#0000FF" - if("navy") - return "#000080" - if("teal") - return "#008080" - if("purple") - return "#800080" - if("indigo") - return "#4B0082" - else - return "#FFFFFF" - -/// Converts "#RRGGBB" to list(0xRR, 0xGG, 0xBB) -/proc/hex2rgb(color) - var/r = hex2num(copytext(color, 2, 4)) - var/g = hex2num(copytext(color, 4, 6)) - var/b = hex2num(copytext(color, 6, 8)) - return list(r, g, b) - //This is a weird one: //It returns a list of all var names found in the string //These vars must be in the [var_name] format @@ -428,13 +311,6 @@ GLOBAL_LIST_INIT(modulo_angle_to_dir, list(NORTH,NORTHEAST,EAST,SOUTHEAST,SOUTH, if(var_source.vars.Find(A)) . += A -//assumes format #RRGGBB #rrggbb -/proc/color_hex2num(A) - if(!A || length(A) != length_char(A)) - return 0 - var/rgb = hex2rgb(A) - return rgb[1] + rgb[2] + rgb[3] - //word of warning: using a matrix like this as a color value will simplify it back to a string after being set /proc/color_hex2color_matrix(string) var/length = length(string) diff --git a/code/modules/awaymissions/super_secret_room.dm b/code/modules/awaymissions/super_secret_room.dm index eddd5e0ab0a..b3e81e9a5cd 100644 --- a/code/modules/awaymissions/super_secret_room.dm +++ b/code/modules/awaymissions/super_secret_room.dm @@ -126,7 +126,7 @@ /obj/item/rupee/Initialize(mapload) . = ..() - var/newcolor = color2hex(pick(10;"green", 5;"blue", 3;"red", 1;"purple")) + var/newcolor = pick(10;COLOR_GREEN, 5;COLOR_BLUE, 3;COLOR_RED, 1;COLOR_PURPLE) add_atom_colour(newcolor, FIXED_COLOUR_PRIORITY) var/static/list/loc_connections = list( COMSIG_ATOM_ENTERED = .proc/on_entered, diff --git a/code/modules/client/preferences/skin_tone.dm b/code/modules/client/preferences/skin_tone.dm index 60e71da430a..119fd6a86a3 100644 --- a/code/modules/client/preferences/skin_tone.dm +++ b/code/modules/client/preferences/skin_tone.dm @@ -14,8 +14,7 @@ var/list/to_hex = list() for (var/choice in get_choices()) var/hex_value = skintone2hex(choice) - var/list/rgb = hex2rgb("#[hex_value]") - var/list/hsl = rgb2hsl(rgb[1], rgb[2], rgb[3]) + var/list/hsl = rgb2num(hex_value, COLORSPACE_HSL) to_hex[choice] = list( "lightness" = hsl[3], diff --git a/code/modules/modular_computers/computers/item/computer_ui.dm b/code/modules/modular_computers/computers/item/computer_ui.dm index c95f9ab59a9..45f8805a4ca 100644 --- a/code/modules/modular_computers/computers/item/computer_ui.dm +++ b/code/modules/modular_computers/computers/item/computer_ui.dm @@ -182,7 +182,7 @@ new_color = input(user, "Choose a new color for [src]'s flashlight.", "Light Color",light_color) as color|null if(!new_color) return - if(color_hex2num(new_color) < 200) //Colors too dark are rejected + if(is_color_dark(new_color, 50) ) //Colors too dark are rejected to_chat(user, span_warning("That color is too dark! Choose a lighter one.")) new_color = null return set_flashlight_color(new_color) diff --git a/code/modules/wiremod/components/action/light.dm b/code/modules/wiremod/components/action/light.dm index 61c1f65ef5c..46fd2993a9d 100644 --- a/code/modules/wiremod/components/action/light.dm +++ b/code/modules/wiremod/components/action/light.dm @@ -20,7 +20,7 @@ var/datum/port/input/on var/max_power = 5 - var/min_lightness = 0.4 + var/min_lightness = 40 var/shell_light_color /obj/item/circuit_component/light/get_ui_notices() @@ -48,9 +48,8 @@ red.set_value(clamp(red.value, 0, 255)) blue.set_value(clamp(blue.value, 0, 255)) green.set_value(clamp(green.value, 0, 255)) - var/list/hsl = rgb2hsl(red.value || 0, green.value || 0, blue.value || 0) - var/list/light_col = hsl2rgb(hsl[1], hsl[2], max(min_lightness, hsl[3])) - shell_light_color = rgb(light_col[1], light_col[2], light_col[3]) + var/list/hsl = rgb2num(rgb(red.value || 0, green.value || 0, blue.value || 0), COLORSPACE_HSL) + shell_light_color = rgb(hsl[1], hsl[2], max(min_lightness, hsl[3]), space=COLORSPACE_HSL) /obj/item/circuit_component/light/input_received(datum/port/input/port) if(parent.shell)