X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2Fmode%2FTwoColorNoiseMode.java;h=6e8de55480e07d4b40cf93b88756a1b2f697cd2e;hb=0c8d61b6afd2f094eadae092ed9a5c6f6adc0760;hp=1ebb93021fd569fa492d05f062b328ea7b428399;hpb=baaaa10bd2e30428f8ca0f04855a24138e70d097;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/mode/TwoColorNoiseMode.java b/src/kaka/cakelight/mode/TwoColorNoiseMode.java index 1ebb930..6e8de55 100644 --- a/src/kaka/cakelight/mode/TwoColorNoiseMode.java +++ b/src/kaka/cakelight/mode/TwoColorNoiseMode.java @@ -1,34 +1,23 @@ package kaka.cakelight.mode; import kaka.cakelight.Color; -import kaka.cakelight.Console; import kaka.cakelight.LedFrame; import kaka.cakelight.util.SimplexNoise3D; public class TwoColorNoiseMode extends AmbientMode { - private final Color primary, secondary; + // private final Color primary, secondary; + private final Color[] colors; private SimplexNoise3D noise = new SimplexNoise3D(0); - public static Console.Command getCommand() { - return new Console.Command() { - public String[] getNames() { - return new String[] {"n", "noise"}; - } - - public void activate(Console console, String[] args) { - if (args.length == 3) { // cmd + col1 + col2 - console.getCakelight().setMode(new TwoColorNoiseMode( - parseColor(args[1]), - parseColor(args[2]) - )); - } - } - }; + public TwoColorNoiseMode(Color... colors) { + assert colors.length > 1; + this.colors = colors; } public TwoColorNoiseMode(Color primary, Color secondary) { - this.primary = primary; - this.secondary = secondary; + this(new Color[] {primary, secondary}); +// this.primary = primary; +// this.secondary = secondary; } @Override @@ -37,7 +26,19 @@ public class TwoColorNoiseMode extends AmbientMode { double x = frame.xOf(i); double y = frame.yOf(i); double v = Math.pow(Math.min(1, Math.max(0, noise.getr(0.0, 1.0, 1, x, y, time / 7000.0))), 1.5); - frame.setLedColor(i, primary.interpolate(secondary, v)); + // frame.setLedColor(i, primary.interpolate(secondary, v)); + frame.setLedColor(i, getColorAt(v)); } } + + private Color getColorAt(double value) { // 0.0 to 1.0 + double localRange = 1.0 / (colors.length - 1); + int index = (int)(value / localRange); + double localValue = (value / localRange) - index; + if (index == colors.length - 1) { + return colors[colors.length - 1]; + } else { + return colors[index].interpolate(colors[index + 1], localValue); + } + } }