모듈:WeatherBoxColors

토끼 (토론 | 기여)님의 2019년 2월 18일 (월) 12:00 판 (새 문서: w = {}; math_mod = require( 'Module:Math' ); function hex( value ) return string.format("%02X", value) end function format_line( background, text_color ) return table.concat...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

w = {}; math_mod = require( 'Module:Math' );

function hex( value ) return string.format("%02X", value) end

function format_line( background, text_color ) return table.concat( {"background: #", background, "; color:#", text_color, ";"} ); end

function range_pos( value, start, stop ) if start < stop thenif value < start thenreturn 0; elseif value > stop thenreturn 1; elsereturn (value - start) / (stop - start); end elseif value < stop thenreturn 1; elseif value > start thenreturn 0; elsereturn (start - value) / (start - stop); end end end

function w.color_d( frame ) local val = math_mod._cleanNumber( frame.args[1] );return w._days_color( val ); end function w.color_pastel( frame ) local val = math_mod._cleanNumber( frame.args[1] );return w._pastel_color( val ); end function w.color_t( frame ) local val = math_mod._cleanNumber( frame.args[1] );return w._temperature_color( val ); end function w.color_green( frame ) local val = math_mod._cleanNumber( frame.args[1] );return w._green_color( val ); end function w.color_s( frame ) local val = math_mod._cleanNumber( frame.args[1] );return w._sunshine_color( val ); end function w.color_h( frame ) local val = math_mod._cleanNumber( frame.args[1] );return w._humidity_color( val ); end function w.color_p( frame ) local val = math_mod._cleanNumber( frame.args[1] );return w._precipitation_color( val ); end

function w._days_color( val ) local item, background, text_color;if val == nil thenreturn format_line( "FFFFFF", "000000" ); enditem = hex( range_pos( val, 20, 0 )*255 );background = item .. item;item = hex( range_pos( val, 40, 20 )*255 );background = background .. item; if val >= 12 thentext_color = "FFFFFF"; elsetext_color = "000000"; end return format_line( background, text_color ); end

function w._green_color( val ) local item1, item2, background, text_color;if val == nil thenreturn format_line( "FFFFFF", "000000" ); enditem1 = hex( range_pos( val, 165.6, 0 )*255 );item2 = hex( range_pos( val, 300, 165.61 )*207 + 48 );background = table.concat( { item1, item2, item1 } ); if val >= 200 thentext_color = "FFFFFF"; elsetext_color = "000000"; end return format_line( background, text_color ); end

function w._temperature_color( val ) local item, background, text_color;if val == nil thenreturn format_line( "FFFFFF", "000000" ); endif val < 4.5 thenitem = range_pos( val, -42.75, 4.5 )*255;background = hex( item ); else item = range_pos( val, 60, 41.5 )*255;background = hex( item ); endif val <= 4.5 thenitem = range_pos( val, -42.75, 4.5 )*255;background = background .. hex( item ); elseitem = range_pos( val, 41.5, 4.5 )*255;background = background .. hex( item ); end if val < -42.78 thenitem = range_pos( val, -90, -42.78 )*255;background = background .. hex( item ); else item = range_pos( val, 23, 4.5 )*255;background = background .. hex( item ); endif val < -23.3 or val >= 37.8 thentext_color = "FFFFFF"; elsetext_color = "000000"; endreturn format_line( background, text_color ); end

function w._precipitation_color( val ) local item, background, text_color;if val == nil thenreturn format_line( "FFFFFF", "000000" ); enditem = hex( range_pos( val, 165.6, 0 )*255 );background = item .. item;item = hex( range_pos( val, 300, 165.61 )*207 + 48 );background = background .. item;if val > 90 thentext_color = "FFFFFF"; else text_color = "000000"; end

return format_line( background, text_color ); end

function w._humidity_color( val ) local item, background, text_color;if val == nil thenreturn format_line( "FFFFFF", "000000" ); enditem = hex( range_pos( val, 66.67, 0 )*255 );background = item .. item;item = hex( range_pos( val, 133.33, 66.667 )*255 );background = background .. item;if val >= 40 thentext_color = "FFFFFF"; else text_color = "000000"; end

return format_line( background, text_color ); end

function w._sunshine_color( val ) local item, background, text_color;if val == nil thenreturn format_line( "FFFFFF", "000000" ); endif val < 90 thenitem = hex( range_pos( val, 0, 90 )*170 ); elseif val < 180 thenitem = hex( range_pos( val, 90, 180 )*42.5 + 170 ); elseitem = hex( range_pos( val, 180, 360 )*42.5 + 212.5 ); end background = item .. item;if val < 90 thenitem = hex( range_pos( val, 0, 90 )*170 ); elseif val < 270 thenitem = hex( range_pos( val, 150, 90 )*170 ); elseitem = hex( range_pos( val, 270, 720 )*255 ); end background = background .. item;if val < 80 thentext_color = "FFFFFF"; else text_color = "000000"; end

return format_line( background, text_color ); end

function w._pastel_color( val ) local item, background, text_color;if val == nil thenreturn format_line( "FFFFFF", "000000" ); end

if val < -15 or val >= 39 thentext_color = "FFFFFF"; else text_color = "000000"; endif val >= 51 thenbackground = 'EE2200'; elseval = math_mod._round( (val + 25.5)/3, 0 );if val == 1 thenbackground = 'BB00CC'; elseif val == 2 thenbackground = 'CC00EE'; elseif val == 3 thenbackground = 'CC33EE'; elseif val == 4 thenbackground = 'CC55EE'; elseif val == 5 thenbackground = 'DD66EE'; elseif val == 6 thenbackground = 'DD77EE'; elseif val == 7 thenbackground = 'DD99EE'; elseif val == 8 thenbackground = 'DDAAEE'; elseif val == 9 thenbackground = 'DDBBEE'; elseif val == 10 thenbackground = 'EECCFF'; elseif val == 11 thenbackground = 'FFDDFF'; elseif val == 12 thenbackground = 'F1F1F1'; elseif val == 13 thenbackground = 'FFEEBB'; elseif val == 14 thenbackground = 'FFFFCC'; elseif val == 15 thenbackground = 'FFFFBB'; elseif val == 16 thenbackground = 'FFFFAA'; elseif val == 17 thenbackground = 'FFFF88'; elseif val == 18 thenbackground = 'FFCC33'; elseif val == 19 thenbackground = 'FFBB33'; elseif val == 20 thenbackground = 'FF9900'; elseif val == 21 thenbackground = 'FF8844'; elseif val == 22 thenbackground = 'FF6633'; elseif val == 23 thenbackground = 'FF5522'; elseif val == 24 thenbackground = 'FF4422'; elseif val == 25 thenbackground = 'EE4400'; elsebackground = 'AA00AA' end end

return format_line( background, text_color ); end

function w._none_color( val ) return format_line( "FAFAFA", "000000" ); end

function w.interpret_color_code( code ) code = code:lower();if code == 't' thenreturn w._temperature_color; elseif code == 'pastel' thenreturn w._pastel_color; elseif code == 'green' thenreturn w._green_color; elseif code == 'h' thenreturn w._humidity_color; elseif code == 's' thenreturn w._sunshine_color; elseif code == 'p' thenreturn w._precipitation_color; elseif code == 'd' thenreturn w._days_color; elseif code == 'none' thenreturn w._none_color; elseerror( '알 수 없는 스킴 옵션' ); end end

return w;