#!/usr/bin/env nu let chapters = { 2: 7, 3: 9, 4: 19, } let gradients = [ [0, [90, 0, 0]], [0.65, [180, 180, 0]], [1, [0, 90, 0]], ] let formatColor = {|color| $"rgb\(($color.0), ($color.1), ($color.2)\)" } let interpColor = {|p| let next = ($gradients | enumerate | skip until { $p <= $in.item.0 } | get index).0 if $next == 0 { return (do $formatColor ($gradients.0.1)) } let prev = ($gradients | get ($next - 1)) let next = ($gradients | get $next) let pp = ($p - $prev.0) / ($next.0 - $prev.0) let color = ($prev.1 | zip $next.1 | each {|a| $a.0 * (1 - $pp) + $a.1 * $pp}) do $formatColor $color } let viz = { |k, n| let ratio = ($k / $n) | math round --precision 1 # let color = if n == 0 { "gray" } else if $ratio < 0.25 { "red" } else if $ratio < 0.5 { "orange"} else if $ratio < 0.75 { "yellow"} else { "green" } let color = if $n == 0 { "gray" } else { do $interpColor ($k / $n) } let textColor = if $k == $n { "gold" } else { "white" } $"