package main import ( "math" "strconv" ) const svgTemplate string = ` coverage coverage {{.Percentage}}% {{.Percentage}}% ` type CoveragePill struct { Percentage string BaseColour string FillColour string } func percentageToRGB(percentage float64) string { red := modifier + clamp(2-2*math.Pow(percentage, 2), 0, 1)*(1-modifier) green := modifier + clamp(2*math.Pow(percentage, 2), 0, 1)*(1-modifier) redValue := strconv.Itoa(int(red * maxValue)) greenValue := strconv.Itoa(int(green * maxValue)) blueValue := strconv.Itoa(blue) return "rgb(" + redValue + ", " + greenValue + ", " + blueValue + ")" } func clamp(operation float64, min float64, max float64) float64 { if operation < min { return min } if operation > max { return max } return operation } func round(num float64) int { return int(num + math.Copysign(0.5, num)) } func toFixed(num float64, precision int) float64 { output := math.Pow(10, float64(precision)) return float64(round(num*output)) / output }