【问题标题】:POV-Ray 2D gradient (polygon)POV-Ray 2D 渐变(多边形)
【发布时间】:2020-01-27 11:41:07
【问题描述】:

所以,我想做的是在自定义 2D 多边形上应用颜色渐变,但我在任何地方都找不到有关如何操作的说明/示例(我只能找到 3D 的)。具体来说,我想这样做:

一般来说,我想知道如何应用一个简单的径向渐变,比如说从(多边形的)中心向外。

【问题讨论】:

    标签: colors 2d gradient povray


    【解决方案1】:

    好的,所以我想通了,因为我似乎无法在任何地方找到一个直截了当的答案,我不妨回答我自己的问题:

    1) 要在多边形上做一个渐变,您只需要带有 color_map 的球形颜料。我举一个三角形的例子:

    #declare pol1=polygon{3,<-1,0> <1,0> <0,1>} //Declare a triangle
    polygon{pol1 pigment{spherical color_map{[0.0 rgb <1,0,0>] [1.0 rgb <0,0,1>] } translate<0,0,0>} }    
    

    所以它的作用是创建一个径向渐变,其中心位于绝对 (0,0,0) 处,您可以根据需要转换它。 color map 定义了两种颜色(rgb 和 rgb ),它们前面的数字基本上控制渐变(颜色开始/结束的位置相对于网格系统)。就不详细解释了,大家可以阅读更多here

    2) 要进行更多渐变,例如每个角一个,我找不到在单个形状上应用 3 种不同渐变的方法。与 color_map 一样,还有一个 gradient_map ,但它没有任何帮助,因为您必须定义一种颜料在哪里结束以及下一种颜料从哪里开始。因此,我发现的唯一方法是用圆柱体(使用difference 命令)移除多边形的角,然后用相位为所需梯度的圆柱体(使用intersection 命令)替换它们。即使这是一种混乱的方式,它实际上并不会影响性能,这是我主要关心的问题,所以我会继续使用它,直到找到更好的东西。所以这里是一个例子(我不打算再解释了,这个答案越来越大了):

    #declare pos1=array[2]{-1,0}; //the corners' coordinates
    #declare pos2=array[2]{1,0};   
    #declare pos3=array[2]{0,1};
    #declare cyl_rad=0.5;     
    
    #declare pol1=polygon{3,<pos1[0],pos1[1],0> <pos2[0],pos2[1],0> <pos3[0],pos3[1],0>} //Declare the polygon
    #declare cyl1=cylinder{<pos1[0],pos1[1],-0.01> <pos1[0],pos1[1],0.01>,cyl_rad} //Declare the cylinder that will "replace" the first corner
    #declare cyl2=cylinder{<pos2[0],pos2[1],-0.01> <pos2[0],pos2[1],0.01>,cyl_rad} //Declare the cylinder that will "replace" the second corner
    #declare cyl3=cylinder{<pos3[0],pos3[1],-0.01> <pos3[0],pos3[1],0.01>,cyl_rad} //Declare the cylinder that will "replace" the third corner
    difference{polygon{pol1} cyl1 cyl2 cyl3 pigment {color_part}} //The polygon with its corners "cut"
    intersection{polygon{pol1} cyl3 pigment{spherical color_map{[0.0 rgb <1,0,0>] [0.95 rgb <0,0,1>]} scale<cyl_rad,cyl_rad,cyl_rad> translate <pos3[0],pos3[1],0>} } //Replacing the corners with the coloured cylinders
    intersection{polygon{pol1} cyl2 pigment{spherical color_map{[0.0 rgb <1,0,0>] [0.95 rgb <0,1,1>]} scale<cyl_rad,cyl_rad,cyl_rad> translate <pos2[0],pos2[1],0>} }
    intersection{polygon{pol1} cyl1 pigment{spherical color_map{[0.0 rgb <1,0,0>] [0.95 rgb <0,1,0>]} scale<cyl_rad,cyl_rad,cyl_rad> translate <pos1[0],pos1[1],0>} }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-02
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      相关资源
      最近更新 更多