From 242486dc84c4f5b0c1bfad9807099355246f4ee2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Sun, 23 Apr 2017 15:54:23 +0200 Subject: [PATCH] Added a custom Color class --- src/kaka/cakelight/Color.java | 34 ++++++++++++++++++++++++++++++++++ src/kaka/cakelight/Frame.java | 1 - src/kaka/cakelight/GuiTest.java | 13 +++++++++---- src/kaka/cakelight/LedFrame.java | 2 -- 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 src/kaka/cakelight/Color.java diff --git a/src/kaka/cakelight/Color.java b/src/kaka/cakelight/Color.java new file mode 100644 index 0000000..ba85866 --- /dev/null +++ b/src/kaka/cakelight/Color.java @@ -0,0 +1,34 @@ +package kaka.cakelight; + +public class Color { + private int r, g, b; + + public static Color rgb(int r, int g, int b) { + Color c = new Color(); + c.r = r; + c.g = g; + c.b = b; + return c; + } + + public int r() { + return r; + } + + public int g() { + return g; + } + + public int b() { + return b; + } + + public Color interpolate(Color other, double value) { + double invertedValue = 1 - value; + return Color.rgb( + (int)(r * invertedValue + other.r * value), + (int)(g * invertedValue + other.g * value), + (int)(b * invertedValue + other.b * value) + ); + } +} diff --git a/src/kaka/cakelight/Frame.java b/src/kaka/cakelight/Frame.java index 192f013..7b94eb9 100644 --- a/src/kaka/cakelight/Frame.java +++ b/src/kaka/cakelight/Frame.java @@ -1,6 +1,5 @@ package kaka.cakelight; -import javafx.scene.paint.Color; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.Size; diff --git a/src/kaka/cakelight/GuiTest.java b/src/kaka/cakelight/GuiTest.java index b73d37f..a8da351 100644 --- a/src/kaka/cakelight/GuiTest.java +++ b/src/kaka/cakelight/GuiTest.java @@ -63,6 +63,11 @@ public class GuiTest extends Application { mode.onVideoFrame(frame -> drawFrame(canvas.getGraphicsContext2D(), frame)); } + private javafx.scene.paint.Color getLedColor(LedFrame frame, int led) { + kaka.cakelight.Color c = frame.getLedColor(led); + return javafx.scene.paint.Color.rgb(c.r(), c.g(), c.b()); + } + private void drawFrame(GraphicsContext gc, Frame frame) { if (paused) return; System.out.println("Drawing a frame"); @@ -78,15 +83,15 @@ public class GuiTest extends Application { float rowSize = 9f * BLOCK / config.leds.rows; // DropShadow shadow = new DropShadow(BlurType.ONE_PASS_BOX, Color.RED, colSize * 2, colSize, 0, 0); for (int x = 0; x < config.leds.cols; x++) { - gc.setFill(frame.getLedColor(x + config.leds.rows)); + gc.setFill(getLedColor(frame, x + config.leds.rows)); gc.fillRect(GUTTER + x * colSize, GUTTER - ledLength, colSize, ledLength); - gc.setFill(frame.getLedColor(config.leds.rows * 2 + config.leds.cols * 2 - 1 - x)); + gc.setFill(getLedColor(frame, config.leds.rows * 2 + config.leds.cols * 2 - 1 - x)); gc.fillRect(GUTTER + x * colSize, GUTTER + 9 * BLOCK, colSize, ledLength); } for (int y = 0; y < config.leds.rows; y++) { - gc.setFill(frame.getLedColor(config.leds.rows - 1 - y)); + gc.setFill(getLedColor(frame, config.leds.rows - 1 - y)); gc.fillRect(GUTTER - ledLength, GUTTER + y * rowSize, ledLength, rowSize); - gc.setFill(frame.getLedColor(y + config.leds.rows + config.leds.cols)); + gc.setFill(getLedColor(frame, y + config.leds.rows + config.leds.cols)); gc.fillRect(GUTTER + 16 * BLOCK, GUTTER + y * rowSize, ledLength, rowSize); } } diff --git a/src/kaka/cakelight/LedFrame.java b/src/kaka/cakelight/LedFrame.java index a4f6293..f739e38 100644 --- a/src/kaka/cakelight/LedFrame.java +++ b/src/kaka/cakelight/LedFrame.java @@ -1,7 +1,5 @@ package kaka.cakelight; -import javafx.scene.paint.Color; - public class LedFrame { private Color[] leds; -- 2.11.0