Skip to content

Commit

Permalink
Фиксы после разделения
Browse files Browse the repository at this point in the history
  • Loading branch information
msw7007 committed Dec 20, 2024
1 parent 90cf44f commit 70718b1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions modular_bandastation/_helpers220/_helpers220.dme
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "_helpers220.dm"

#include "code/unsorted.dm"
#include "code/type2type.dm"
60 changes: 60 additions & 0 deletions modular_bandastation/_helpers220/code/type2type.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Holds procs designed to change one type of value, into another.
* Contains:
* hex2num & num2hex
* file2list
* angle2dir
* angle2text
* worldtime2text
*/

//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

0 comments on commit 70718b1

Please sign in to comment.