Switched to rgba standard. Quite possibly this will mess something up :)

This commit is contained in:
Grant Sanderson
2017-09-19 13:12:45 -07:00
parent ca4f540389
commit bb958b68d7
12 changed files with 109 additions and 68 deletions

View File

@ -109,21 +109,32 @@ def diag_to_matrix(l_and_u, diag):
def is_closed(points):
return np.linalg.norm(points[0] - points[-1]) < CLOSED_THRESHOLD
## Color
def color_to_rgb(color):
return np.array(Color(color).get_rgb())
def color_to_rgba(color, alpha = 1):
return np.append(color_to_rgb(color), [alpha])
def rgb_to_color(rgb):
try:
return Color(rgb = rgb)
except:
return Color(WHITE)
def rgba_to_color(rgba):
return rgb_to_color(rgba[:3])
def invert_color(color):
return rgb_to_color(1.0 - color_to_rgb(color))
def color_to_int_rgb(color):
return (255*color_to_rgb(color)).astype('uint8')
def color_to_int_rgba(color, alpha = 255):
return np.append(color_to_int_rgb(color), alpha)
def color_gradient(reference_colors, length_of_output):
if length_of_output == 0:
return reference_colors[0]
@ -148,6 +159,8 @@ def average_color(*colors):
mean_rgb = np.apply_along_axis(np.mean, 0, rgbs)
return rgb_to_color(mean_rgb)
###
def compass_directions(n = 4, start_vect = RIGHT):
angle = 2*np.pi/n
return np.array([