From 65af4342c4259d9b99de31a65be58cb1ec4e524d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Wed, 3 May 2017 12:15:51 +0200 Subject: [PATCH] New shifting color mode --- src/kaka/cakelight/AmbientMode.java | 15 +++++++++++++-- src/kaka/cakelight/Color.java | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/kaka/cakelight/AmbientMode.java b/src/kaka/cakelight/AmbientMode.java index a6ae8da..0b41b4c 100644 --- a/src/kaka/cakelight/AmbientMode.java +++ b/src/kaka/cakelight/AmbientMode.java @@ -62,10 +62,21 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St } } else if (type == 1) { for (int i = 0; i < config.leds.getCount(); i++) { - double g = noise.getr(0, 0.5, 0.5, frame.xOf(i), frame.yOf(i), time / 5000.0); - double b = noise.getr(0, 1, 1, frame.xOf(i), frame.yOf(i), time / 7000.0); + double x = frame.xOf(i); + double y = frame.yOf(i); + double g = Math.min(1, Math.max(0, noise.getr(-0.5, 0.5, 0.5, x, y, time / 5000.0))); + double b = Math.pow(Math.min(1, Math.max(0, noise.getr(0, 0.9, 1, x, y, time / 7000.0))), 2); frame.setLedColor(i, Color.rgb(0, g, b)); } + } else if (type == 2) { + int ledCount = config.leds.getCount(); + double hueOffset = time * 0.00001; + double hueLength = 1.0 / 6; + for (int i = 0; i < config.leds.getCount(); i++) { + double ledOffset = (i + (hueOffset * ledCount)) % ledCount; + double value = Math.abs((ledOffset * 2 - ledCount) / ledCount); // 1 to 0 to 1 + frame.setLedColor(i, Color.hsv(value * hueLength + hueOffset, 1, 1)); + } } } diff --git a/src/kaka/cakelight/Color.java b/src/kaka/cakelight/Color.java index da09127..1e92da9 100644 --- a/src/kaka/cakelight/Color.java +++ b/src/kaka/cakelight/Color.java @@ -15,6 +15,25 @@ public class Color { return c; } + public static Color hsv(double hue, double saturation, double value) { + double normalizedHue = hue - Math.floor(hue); + int h = (int)(normalizedHue * 6); + double f = normalizedHue * 6 - h; + double p = value * (1 - saturation); + double q = value * (1 - f * saturation); + double t = value * (1 - (1 - f) * saturation); + + switch (h) { + case 0: return rgb(value, t, p); + case 1: return rgb(q, value, p); + case 2: return rgb(p, value, t); + case 3: return rgb(p, q, value); + case 4: return rgb(t, p, value); + case 5: return rgb(value, p, q); + default: throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value); + } + } + public int r() { return r; } -- 2.11.0