| 1 | package kaka.cakelight.mode; |
| 2 | |
| 3 | import kaka.cakelight.Color; |
| 4 | import kaka.cakelight.Console; |
| 5 | import kaka.cakelight.LedFrame; |
| 6 | import kaka.cakelight.util.SimplexNoise3D; |
| 7 | |
| 8 | public class TwoColorNoiseMode extends AmbientMode { |
| 9 | private final Color primary, secondary; |
| 10 | private SimplexNoise3D noise = new SimplexNoise3D(0); |
| 11 | |
| 12 | public static Console.Command getCommand() { |
| 13 | return new Console.Command() { |
| 14 | @Override |
| 15 | public String[] getNames() { |
| 16 | return new String[] {"n", "noise"}; |
| 17 | } |
| 18 | |
| 19 | @Override |
| 20 | public void activate(Console console, String[] args) { |
| 21 | if (args.length == 2) { // col1 + col2 |
| 22 | console.getCakelight().setMode(new TwoColorNoiseMode( |
| 23 | parseColor(args[0]), |
| 24 | parseColor(args[1]) |
| 25 | )); |
| 26 | output("setting two-color noise mode"); |
| 27 | } |
| 28 | } |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | public TwoColorNoiseMode(Color primary, Color secondary) { |
| 33 | this.primary = primary; |
| 34 | this.secondary = secondary; |
| 35 | } |
| 36 | |
| 37 | @Override |
| 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)); |
| 44 | } |
| 45 | } |
| 46 | } |