Something similar is done for complex functions by using the domain coloring technique. First I will explain the idea, and then the application for your case:
A graph of a complex function $g : \Bbb C \to \Bbb C $ of one complex variable lives in a space with two complex dimensions. Since the complex plane itself is two-dimensional, a graph of a complex function is an object in four real dimensions. That makes complex functions difficult to visualize in a three-dimensional space.
The domain coloring technique transforms the points belonging to $f(z)$ into hue, brightness and saturation values, all normalized into $[0,1]$. Usually the argument of the complex number $f(z)$ is converted into a normalized value $[0,1]$ and then associated to a hue value. Then the color associated to $f(z)$ is shown at the position $z$.
In your case you do not have a complex number, but you can use an application of this technique by replacing the argument (angle) of the complex number by the angle of the slope between the two points you are linking (as Arthur said in the comments). This will provide you an $RGB$ triplet based on the value of the angle of the slope that you can use with your favorite programming language to draw the line between the points according to a specific color. Credits of the original ideas in the comments inside the Python code. Please feel free to use it and modify it:
def getting_RGB_from_angle():
from math import pi
def hslToRgb(h, s, l):
# Source of this function: https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion
# Converts an HSL color value to RGB. Conversion formula
# adapted from http://en.wikipedia.org/wiki/HSL_color_space.
# Assumes h, s, and l are contained in the set [0, 1] and
# returns r, g, and b in the set [0, 1].
def hue2rgb(p, q, t):
if t < 0:
t += 1
if t > 1:
t -= 1
if t < 1/6:
return p + (q - p) * 6 * t
if t < 1/2:
return q
if t < 2/3:
return p + (q - p) * (2/3 - t) * 6
return p
r,g,b = 0,0,0
if s == 0:
r,g,b = l,l,l
else:
q=0
if l < 0.5:
q=l * (1 + s)
else:
q=l + s - l * s
p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3)
g = hue2rgb(p, q, h)
b = hue2rgb(p, q, h - 1/3)
return r,g,b
# example
current_angle = pi/3
r,g,b = hslToRgb(current_angle, 0.5, 0.7) #hslToRgb(hue,saturation,luminance)
print("Current angle: "+str(current_angle)+"\t Normalized (r,g,b)=("+str(r)+","+str(g)+","+str(b)+")")
# main
getting_RGB_from_angle()
Above is the easiest setting. The angle of the slope will be the normalized value (normalized means that the value is in the range $[0,1]$, several programming languages are able to use those values to print directly the correct $RGB$ color, for instance Python) of the hue of the $RGB$ color, and the saturation and luminance values will be fixed (initially we do not need to make them dynamic, but you could make them variable if you wish to add some rules regarding those values too).