所以我要做的是。。。你知道吗
假设我使用了“彩虹”效果,它将使用字体标记生成字符串并给它一个“彩虹”效果。但是彩虹渐变效果会延伸到文本的长度,并且颜色不会重复。你知道吗
我的意思是:
字符串“Rainbow”将生成以下代码:
<font color="#ff0000">R</font><font color="#ff7f00">a</font><font color="#ffff00">i</font><font color="#00ff00">n</font><font color="#00ffff">b</font><font color="#0000ff">o</font><font color="#8b00ff">w</font>
看看彩虹的7种颜色如何与文本的7个字母相匹配?现在让我们假设文本更长。我是说,再长一点。你知道吗
字符串“rainboooow”需要适应其中的所有渐变,同时以“#ff0000”标记开始,以“#8b00ff”标记结束,而不重复任何相同的颜色。这意味着我需要以某种方式在两者之间“生成”字体颜色。所以这个字符串会产生如下结果:
<font color="#ff0000">R</font><font color="#ff2000">a</font><font color="#ff4000">i</font><font color="#ff5f00">n</font><font color="#ff7f00">b</font><font color="#ff9f00">o</font><font color="#ffbf00">o</font><font color="#ffdf00">o</font><font color="#ffff00">o</font><font color="#bfff00">o</font><font color="#80ff00">o</font><font color="#40ff00">o</font><font color="#00ff00">o</font><font color="#00ff55">o</font><font color="#00ffaa">o</font><font color="#00ffff">o</font><font color="#00bfff">o</font><font color="#0080ff">o</font><font color="#0040ff">o</font><font color="#0000ff">o</font><font color="#2300ff">o</font><font color="#4600ff">o</font><font color="#6800ff">o</font><font color="#8b00ff">w</font>
如何在python中执行此操作?我一直在想办法,但我就是不能。。。我们将不胜感激。你知道吗
有趣的问题!我认为一个简单的方法是使用hue, saturation and luminance (or lightness) (HSL) color model。利用这种颜色模型,通过改变彩虹的色调,保持彩虹的饱和度和亮度不变,可以得到彩虹的所有颜色。你知道吗
为了在Python中实现这一点,我们可以使用colour模块。我用这个函数创建了一个彩虹颜色列表,然后再创建一个函数,将这些
Color
对象转换为它们的十六进制表示:注意:如果您不想将颜色环绕,请将
get_rainbow_colors
中的(length - 1)
更改为length
,即第一种颜色始终为红色,length - 1
最后一种颜色也为红色,但仅length
最后一种颜色将为蓝色/紫色。你知道吗最后我做了一个函数,将一个单词转换成HTML文本,每个字符都有一个单独的颜色。你知道吗
此函数为单词rainbow提供以下输出:
<font color="#ff0000">r</font><font color="#ffff00">a</font><font color="#00ff00">i</font><font color="#00ffff">n</font><font color="#0000ff">b</font><font color="#ff00ff">o</font><font color="#ff0000">w</font>
matplotlib示例
完整的代码
相关问题 更多 >
编程相关推荐