From 8304abc8107c4c4d7334ddc7276e95b8f535ee55 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Tue, 24 Sep 2019 22:01:11 +0200 Subject: [PATCH] New smooth video mode that mixes the new frame with the previous one --- src/kaka/cakelight/Main.java | 2 +- src/kaka/cakelight/SmoothVideoMode.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/kaka/cakelight/SmoothVideoMode.java diff --git a/src/kaka/cakelight/Main.java b/src/kaka/cakelight/Main.java index 56761f2..dd3c1f7 100644 --- a/src/kaka/cakelight/Main.java +++ b/src/kaka/cakelight/Main.java @@ -17,7 +17,7 @@ public class Main { if (args.length > 0) { cakelight.setMode(new AmbientMode(args)); } else { - cakelight.setMode(new VideoMode()); + cakelight.setMode(new SmoothVideoMode()); } cakelight.startLoop(); Runtime.getRuntime().addShutdownHook(new Thread(Main::printTimeStats)); diff --git a/src/kaka/cakelight/SmoothVideoMode.java b/src/kaka/cakelight/SmoothVideoMode.java new file mode 100644 index 0000000..e9ef442 --- /dev/null +++ b/src/kaka/cakelight/SmoothVideoMode.java @@ -0,0 +1,26 @@ +package kaka.cakelight; + +public class SmoothVideoMode extends VideoMode { + private LedFrame frame; + private int ledCount; + + @Override + public void enter(Configuration config) { + super.enter(config); + frame = LedFrame.from(config); + ledCount = config.leds.getCount(); + } + + @Override + public void updateWithFrame(LedFrame frame) { + super.updateWithFrame(smooth(frame)); + } + + private LedFrame smooth(LedFrame f) { + for (int i = 0; i < ledCount; i++) { + Color c = frame.getLedColor(i).interpolate(f.getLedColor(i), 0.5); + frame.setLedColor(i, c); + } + return frame; + } +} -- 2.11.0