0

为什么下面的代码会导致块状渐变?即渐变不平滑,您可以看到一些组成它的矩形。

有没有办法来解决这个问题?
顺便说一句,我在 Vista 上运行它,但我也在 Mac 上体验过。

var stage:Stage = Stage {
title: "Louis' Photo Wall"
width: 900
height: 600

scene: Scene {
    content : Rectangle {
        width:  bind stage.scene.width
        height: bind stage.scene.height
        fill:LinearGradient {
            startX : 0.0
            startY : 0.0
            endX : 0.0
            endY : 1.0
            stops: [
                Stop {
                    color : Color {
                        red:0.0
                        blue:0.0
                        green:0.0
                    }

                    offset: 0.0
                },
                Stop {
                    color : Color {
                        red:0.8
                        blue:0.8
                        green:0.8
                    }
                    offset: 1.0
                },

            ]
        }

    }//OuterRectangle
}

}

4

1 回答 1

0

块状的数量并不引人注目。

移动到 1.0 的 endX 似乎给出了更明显的变化,块状结果的对角化。

一个假设是有几件事正在发生。1. r/g/b 颜色并不是真正连续的,而是有 256 步。(8 位)。255 中的 0.8 是 204。 2. 当一个颜色从 0 到 0.8 映射到 600 个像素时,每个像素都会增加一个不能完全平滑的增量。当我跑步时,场景大小实际上是 792x566。因此,渐变将使用 566/204 = 2.775 像素用于一种颜色,然后再转移到另一种颜色。这会导致进行转换的地方出现波动。

这并不能解释为什么使用 0.0 到 1.0 的停止(而不是 0.0 到 0.8)会导致(至少在我的运行中)似乎是一个平滑的过渡。


追问:ofTheWayLinearGradient 有一种可能用于插值的方法。代码示例和结果...

for (v in [0.00..1.00 step 1.0/600]) {
   println("{%7.5f v} {Color.WHITE.ofTheWay(Color.BLACK,v)}");
}

哪个打印

0.00000 javafx.scene.paint.Color[red=255,green=255,blue=255,opacity=1.0]
0.00167 javafx.scene.paint.Color[red=255,green=255,blue=255,opacity=1.0]
0.00333 javafx.scene.paint.Color[red=254,green=254,blue=254,opacity=1.0]
0.00500 javafx.scene.paint.Color[red=254,green=254,blue=254,opacity=1.0]
0.00667 javafx.scene.paint.Color[red=253,green=253,blue=253,opacity=1.0]
0.00833 javafx.scene.paint.Color[red=253,green=253,blue=253,opacity=1.0]
0.01000 javafx.scene.paint.Color[red=252,green=252,blue=252,opacity=1.0]
0.01167 javafx.scene.paint.Color[red=252,green=252,blue=252,opacity=1.0]
0.01333 javafx.scene.paint.Color[red=252,green=252,blue=252,opacity=1.0]
0.01500 javafx.scene.paint.Color[red=251,green=251,blue=251,opacity=1.0]
0.01667 javafx.scene.paint.Color[red=251,green=251,blue=251,opacity=1.0]
...
于 2009-06-01T18:23:30.850 回答