1 package kaka.cakelight.mode;
3 import kaka.cakelight.Color;
4 import kaka.cakelight.Console;
5 import kaka.cakelight.LedFrame;
6 import kaka.cakelight.util.SimplexNoise3D;
8 public class TwoColorNoiseMode extends AmbientMode {
9 private final Color primary, secondary;
10 private SimplexNoise3D noise = new SimplexNoise3D(0);
12 public static Console.Command getCommand() {
13 return new Console.Command() {
15 public String[] getNames() {
16 return new String[] {"n", "noise"};
20 public void activate(Console console, String[] args) {
21 if (args.length == 2) { // col1 + col2
22 console.getCakelight().setMode(new TwoColorNoiseMode(
26 output("setting two-color noise mode");
32 public TwoColorNoiseMode(Color primary, Color secondary) {
33 this.primary = primary;
34 this.secondary = secondary;
38 protected void updateFrame(LedFrame frame, long time, int count) {
39 for (int i = 0; i < config.leds.getCount(); i++) {
40 double x = frame.xOf(i);
41 double y = frame.yOf(i);
42 double v = Math.pow(Math.min(1, Math.max(0, noise.getr(0.0, 1.0, 1, x, y, time / 7000.0))), 1.5);
43 frame.setLedColor(i, primary.interpolate(secondary, v));