【问题标题】:How can I make a gradient background for a graphics box in Mathematica?如何在 Mathematica 中为图形框制作渐变背景?
【发布时间】:2014-01-31 17:19:50
【问题描述】:

我已经看到了有关绘图的这个问题的答案,但我想为一般图形框做这个。

Graphics[{Disk[], Red, Rectangle[{-.75, 1}, {.5, -.5}]}, 
 Background -> Green]

我想让这个图形的背景类似于调色板渐变中的一种。理想情况下,我会在代码中的某处键入“RainbowColors”,背景看起来就像 RainbowColors 调色板。

我可以删除背景并使用渐变填充制作一个矩形,但这并不是我想要的。我希望有人有一些美丽的知识。

非常感谢!!

【问题讨论】:

    标签: graphics background wolfram-mathematica gradient


    【解决方案1】:

    我所知道的最接近的是PrologPolygonVertexColorsScaled 坐标的组合:

    Graphics[
     {Disk[], Red, Rectangle[{-.75, 1}, {.5, -.5}]},
     Prolog ->
      Polygon[
       Scaled /@ {{0, 0}, {0, 1}, {1, 1}, {1, 0}},
       VertexColors -> {Yellow, Green, Magenta, Pink}
      ]
    ]
    

    通过堆叠Polygons可以形成更复杂的渐变:

    Graphics[
     {Disk[], Red, Rectangle[{-.75, 1}, {.5, -.5}]},
     Prolog ->
      {Polygon[
        Scaled /@ {{0, 0}, {0, 1/2}, {1, 1/2}, {1, 0}},
        VertexColors -> {Red, Yellow, Pink, Blue}
       ],
       Polygon[
        Scaled /@ {{0, 1/2}, {0, 1}, {1, 1}, {1, 1/2}},
        VertexColors -> {Yellow, Green, Magenta, Pink}
       ]}
    ]
    

    如果您难以将其转化为函数,请告诉我您遇到的问题,我会尽力提供帮助。


    请在专门的 Mathematica StackExchange 网站上询问您未来的问题:

    【讨论】:

    • 非常感谢。那应该得到我想要的。我绝对会使用 Mathematica StackExchange。我没有意识到它的存在。再次感谢!
    • @Paul 很高兴能帮上忙。再一次,让我知道您是否需要帮助来实现这一点。见Mathematica! :-)
    猜你喜欢
    • 1970-01-01
    • 2020-12-24
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多