You could convert this answer from the post you linked into python:
import math
def num_to_rgb(val, max_val=3):
i = (val * 255 / max_val);
r = round(math.sin(0.024 * i + 0) * 127 + 128);
g = round(math.sin(0.024 * i + 2) * 127 + 128);
b = round(math.sin(0.024 * i + 4) * 127 + 128);
return (r,g,b)
print(num_to_rgb(1.32))
>> (183, 1, 179)
this will return a tuple of three integers (r,g,b).
It is also a good idea to to make sure invalid inputs aren't allowed (aka negatives, or val > max_val):
def num_to_rgb(val, max_val=3):
if (val > max_val):
raise ValueError("val must not be greater than max_val")
if (val < 0 or max_val < 0):
raise ValueError("arguments may not be negative")
i = (val * 255 / max_val);
r = round(math.sin(0.024 * i + 0) * 127 + 128);
g = round(math.sin(0.024 * i + 2) * 127 + 128);
b = round(math.sin(0.024 * i + 4) * 127 + 128);
return (r,g,b)
print(num_to_rgb(4.32))
>> ValueError: val must not be greater than max_val