def color_range_bipolar(v, low, high):
    t = (v - low) / (high - low)
    if t <= 0.5:
        return tui.rgb(tui.gradient((1.0, 0.5, 0.7), (1.0, 1.0, 1.0), t / 0.5))
    else:
        return tui.rgb(
            tui.gradient((1.0, 1.0, 1.0), (0.6, 1.0, 0.5), (t - 0.5) / 0.5))
def _color_for_diff(diff):
    return tui.rgb(
        tui.gradient((0.0, 1.0, 0.0), (1.0, 0.0, 0.0),
                     abs(diff) / 300))
def color_range_cv(v, low, high):
    t = (v - low) / (high - low)
    return tui.rgb(tui.gradient((252, 131, 255), (66, 224, 245), t))
def color_range(v, low, high):
    t = (v - low) / (high - low)
    return tui.rgb(tui.gradient((0.5, 0.5, 0.5), (66, 224, 245), t))
    else:
        return tui.rgb(
            tui.gradient((1.0, 1.0, 1.0), (0.6, 1.0, 0.5), (t - 0.5) / 0.5))


def color_range(v, low, high):
    t = (v - low) / (high - low)
    return tui.rgb(tui.gradient((0.5, 0.5, 0.5), (66, 224, 245), t))


def color_range_cv(v, low, high):
    t = (v - low) / (high - low)
    return tui.rgb(tui.gradient((252, 131, 255), (66, 224, 245), t))


SEEN_COLOR = tui.rgb(0, 0, 0) + tui.rgb(100, 255, 100, fg=False)
COLUMNS = tui.Columns("<3", "<10", "<10", ">7", ">10", ">3")
COLUMNS2 = tui.Columns("<3", "^37", ">3")
SPINNER_FRAMES = "🌑🌒🌓🌔🌕🌖🌗🌘"
SPINNER_FRAME_COUNT = len(SPINNER_FRAMES)
spinner_index = 0


def make_seen_states():
    seen_states = gem_monitor_update.GemMonitorUpdate()
    seen_states.castor_pitch_knob = [False, False]
    seen_states.pollux_pitch_knob = [False, False]
    return seen_states


def track_states(update, seen_states):