基于渐变的条件着色 [英] Conditional coloring based on a gradient
问题描述
请考虑:
操作[
Row [{
图形[Disk []],
Graphics [{
Polygon [{{0,0},{3,0},{3,1},{0,1}},
VertexColors - > {白色,混合[{白色,蓝色}],
混合[{白色,蓝色}],白色}],
黑色,厚,
线[{{i,0}, {i,1}}]},ImageSize - > 300]}],
{i,0,3}]
在渐变填充
怎么可能我使用位于黑线之下的颜色对磁盘进行着色?
这是一种解决方案,因为左侧的颜色是白色
,渐变线性。
With [{max = 3,color = Blend [{White,Blue}]},
操作[
Row [{Graphics [{Opacity [i / max],color,Disk []}],
Graphics [{Polygon [{{0,0},{max,0},{max,1},{0,1}},
VertexColors - > {白色,颜色,颜色,白色}],黑色,厚,
行[{{i,0},{i,1}}]},ImageSize - > 300]}],{i,0,max}]]
如果每一端有两种不同的颜色(即 White
以外的其他颜色), Opacity
方法不起作用。相反,您可以将可选的混合分数参数用于 Blend
所需比例的颜色。这里有一个例子:
$ b $ pre $ 使用[{max = 3,color1 = Red,color2 = Green},
Manipulate [
行{[Graphics [{Blend [{color1,color2},i / max],Disk []}],
Graphics [{Polygon [{{0,0},{max,0} ,{max,1},{0,1}},
VertexColors - > {color1,color2,color2,color1}],黑色,
Thick,Line [{{i,0},{i,1}}]},ImageSize - > 300]}],{i,0,
max}]]
Please consider :
Manipulate[
Row[{
Graphics[Disk[]],
Graphics[{
Polygon[{{0, 0}, {3, 0}, {3, 1}, {0, 1}},
VertexColors -> {White, Blend[{White, Blue}],
Blend[{White, Blue}], White}],
Black, Thick,
Line[{{i, 0}, {i, 1}}]}, ImageSize -> 300]}],
{i, 0, 3}]
Using Szabolcs`s solution on Gradient Filling
How could I color the disk with the color located underneath the Black Line ?
Here is one solution which works because the color on the left is White
and the gradient is linear.
With[{max = 3, color = Blend[{White, Blue}]},
Manipulate[
Row[{Graphics[{Opacity[i/max], color, Disk[]}],
Graphics[{Polygon[{{0, 0}, {max, 0}, {max, 1}, {0, 1}},
VertexColors -> {White, color, color, White}], Black, Thick,
Line[{{i, 0}, {i, 1}}]}, ImageSize -> 300]}], {i, 0, max}]]
If you had two different colors for each end (i.e., something other than White
), the Opacity
approach won't work. Instead, you can use the optional blending fraction argument to Blend
the colors in the desired proportion. Here's an example:
With[{max = 3, color1 = Red, color2 = Green},
Manipulate[
Row[{Graphics[{Blend[{color1, color2}, i/max], Disk[]}],
Graphics[{Polygon[{{0, 0}, {max, 0}, {max, 1}, {0, 1}},
VertexColors -> {color1, color2, color2, color1}], Black,
Thick, Line[{{i, 0}, {i, 1}}]}, ImageSize -> 300]}], {i, 0,
max}]]
这篇关于基于渐变的条件着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!