Commit | Line | Data |
---|---|---|
eca6fd31 TW |
1 | package kaka.cakelight.mode; |
2 | ||
fa013e4b TW |
3 | import kaka.cakelight.Color; |
4 | import kaka.cakelight.Console; | |
5 | import kaka.cakelight.LedFrame; | |
eca6fd31 TW |
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() { | |
35990bbd | 14 | @Override |
eca6fd31 TW |
15 | public String[] getNames() { |
16 | return new String[] {"n", "noise"}; | |
17 | } | |
18 | ||
35990bbd | 19 | @Override |
fa013e4b | 20 | public void activate(Console console, String[] args) { |
35990bbd | 21 | if (args.length == 2) { // col1 + col2 |
fa013e4b | 22 | console.getCakelight().setMode(new TwoColorNoiseMode( |
35990bbd TW |
23 | parseColor(args[0]), |
24 | parseColor(args[1]) | |
eca6fd31 | 25 | )); |
35990bbd | 26 | output("setting two-color noise mode"); |
eca6fd31 TW |
27 | } |
28 | } | |
eca6fd31 TW |
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 | } |