참고 Label
대신 Rectangle
을 사용하는 것이 좋습니다.
또한 HSB 값이 더 적합 할 것 같다 :
- 모든 열은 동일한 색상을 가지고
- 열 전반 휘도 증가하지만 채도 1
- 후반 유지 열의 밝기는 1로 유지되지만 채도는 1에서 0으로 감소합니다.
증분이있는 회색 음영 만 표시되므로 마지막 열은 예외입니다 g 밝기.
다음 코드는 팔레트를 만들 수 있습니다 (또는 적어도 충분히 가깝게) :
@Override
public void start(Stage primaryStage) {
GridPane gridPane = new GridPane();
gridPane.setHgap(4);
gridPane.setVgap(4);
final int columns = 12;
final int rows = 10;
final int fullBrightness = (rows - 1)/2;
final int columnCount = columns - 1;
// fill upper half with full saturation but increasing brightness
for (int y = 0; y <= fullBrightness; y++) {
double brightness = y/(double) fullBrightness;
for (int x = 0; x < columnCount; x++) {
Rectangle rect = new Rectangle(15, 15, Color.hsb(x * (360d/(columns - 1)), 1, brightness));
rect.setStroke(Color.BLACK);
gridPane.add(rect, x, y);
}
}
// fill lower half with full brightness but decreasing saturation
for (int y = fullBrightness + 1; y < rows; y++) {
double saturation = 1 - ((double) (y - fullBrightness))/(columns - 1 - fullBrightness);
for (int x = 0; x < columnCount; x++) {
Rectangle rect = new Rectangle(15, 15, Color.hsb(x * (360d/(columns - 1)), saturation, 1));
rect.setStroke(Color.BLACK);
gridPane.add(rect, x, y);
}
}
// fill last column with grayscale
for (int y = 0, maxIndex = rows - 1; y < rows; y++) {
Rectangle rect = new Rectangle(15, 15, Color.hsb(0, 0, y/(double) maxIndex));
rect.setStroke(Color.BLACK);
gridPane.add(rect, columnCount, y);
}
Scene scene = new Scene(gridPane);
primaryStage.setScene(scene);
primaryStage.show();
}