RGB颜色渐变函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RGB颜色渐变函数相关的知识,希望对你有一定的参考价值。
import string def make_color_tuple( color ): """ turn something like "#000000" into 0,0,0 or "#FFFFFF into "255,255,255" """ R = color[1:3] G = color[3:5] B = color[5:7] R = int(R, 16) G = int(G, 16) B = int(B, 16) return R,G,B def interpolate_tuple( startcolor, goalcolor, steps ): """ Take two RGB color sets and mix them over a specified number of steps. Return the list """ # white R = startcolor[0] G = startcolor[1] B = startcolor[2] targetR = goalcolor[0] targetG = goalcolor[1] targetB = goalcolor[2] DiffR = targetR - R DiffG = targetG - G DiffB = targetB - B buffer = [] for i in range(0, steps +1): iR = R + (DiffR * i / steps) iG = G + (DiffG * i / steps) iB = B + (DiffB * i / steps) hR = string.replace(hex(iR), "0x", "") hG = string.replace(hex(iG), "0x", "") hB = string.replace(hex(iB), "0x", "") if len(hR) == 1: hR = "0" + hR if len(hB) == 1: hB = "0" + hB if len(hG) == 1: hG = "0" + hG color = string.upper("#"+hR+hG+hB) buffer.append(color) return buffer def interpolate( startcolor, goalcolor, steps ): """ wrapper for interpolate_tuple that accepts colors as html ("#CCCCC" and such) """ start_tuple = make_color_tuple(startcolor) goal_tuple = make_color_tuple(goalcolor) return interpolate_tuple(start_tuple, goal_tuple, steps) def printchart(startcolor, endcolor, steps): colors = interpolate(startcolor, endcolor, steps) for color in colors: print color # Example... show us 16 values of gradation between these two colors printchart("#999933", "#6666FF", 16)
以上是关于RGB颜色渐变函数的主要内容,如果未能解决你的问题,请参考以下文章
将 `shap.summary_plot()` 的渐变颜色更改为特定的 2 或 3 RGB 渐变调色板颜色