lib_color
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © robbatt

//@version=5
// @description 
library("lib_color", overlay = true)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © robbatt


// @function get offset color
// @param original original color
// @param offset offset for new color
// @param transparency transparency for new color
// @returns offset color
export offset_mono(simple color original, float offset, float transparency = na) =>
	var r = color.r(original)
	var g = color.g(original)
	var b = color.b(original)
	var t = na(transparency) ? color.t(original) : transparency

	// oscillating values between 0 and 256 with a rising input
	r_off = int(127 * (math.sin(math.toradians(offset + r)) + 1))
	g_off = int(127 * (math.sin(math.toradians(offset + g)) + 1))
	b_off = int(127 * (math.sin(math.toradians(offset + b)) + 1))

	color c_off = color.rgb(r_off, g_off, b_off, t)


//@description automatic detection of dark/light user layout
//@returns boolean status, true: dark mode, false: light mode
is_dark_mode() =>
	var is_dark = color.r(chart.bg_color) < 128 or color.g(chart.bg_color) < 128 or color.b(chart.bg_color) < 128
	is_dark



///////////////////////////////////////////////////////////
// 							TEST
///////////////////////////////////////////////////////////

var test_color = input.color(color.blue, 'base color')
color off_color = offset_mono(test_color, bar_index)
// plot(color.r(off_color) , 'offset color', off_color, linewidth = 4)
// plot(-255, 'fg color, offset -255', offset_mono(test_color, -255), linewidth = 4)
// plot(-224, 'fg color, offset -224', offset_mono(test_color, -224), linewidth = 4)
// plot(-192, 'fg color, offset -192', offset_mono(test_color, -192), linewidth = 4)
// plot(-160, 'fg color, offset -160', offset_mono(test_color, -160), linewidth = 4)
// plot(-128, 'fg color, offset -128', offset_mono(test_color, -128), linewidth = 4)
// plot(-96, 'fg color, offset -96', offset_mono(test_color, -96), linewidth = 4)
// plot(-64, 'fg color, offset -64', offset_mono(test_color, -64), linewidth = 4)
// plot(-32, 'fg color, offset -32', offset_mono(test_color, -32), linewidth = 4)
plot(128, 'fg color', test_color, linewidth = 4)
// plot(3, 'fg color, offset 0', offset_mono(test_color, 0), linewidth = 4)
// plot(32, 'fg color, offset 32', offset_mono(test_color, 32), linewidth = 4)
// plot(64, 'fg color, offset 64', offset_mono(test_color, 64), linewidth = 4)
// plot(96, 'fg color, offset 96', offset_mono(test_color, 96), linewidth = 4)
// plot(128, 'fg color, offset 128', offset_mono(test_color, 128), linewidth = 4)
// plot(160, 'fg color, offset 160', offset_mono(test_color, 160), linewidth = 4)
// plot(192, 'fg color, offset 192', offset_mono(test_color, 192), linewidth = 4)
// plot(224, 'fg color, offset 224', offset_mono(test_color, 224), linewidth = 4)
// plot(255, 'fg color, offset 255', offset_mono(test_color, 255), linewidth = 4)
plotshape(true, 'oscilating indefinite', shape.circle, location.bottom, offset_mono(test_color, bar_index), size = size.small)

plotshape(true, 'is dark mode', shape.circle, location.top, is_dark_mode() ? color.white : color.black, size = size.small)