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() { | |
14 | public String[] getNames() { | |
15 | return new String[] {"n", "noise"}; | |
16 | } | |
17 | ||
fa013e4b | 18 | public void activate(Console console, String[] args) { |
eca6fd31 | 19 | if (args.length == 3) { // cmd + col1 + col2 |
fa013e4b | 20 | console.getCakelight().setMode(new TwoColorNoiseMode( |
eca6fd31 TW |
21 | parseColor(args[1]), |
22 | parseColor(args[2]) | |
23 | )); | |
24 | } | |
25 | } | |
eca6fd31 TW |
26 | }; |
27 | } | |
28 | ||
29 | public TwoColorNoiseMode(Color primary, Color secondary) { | |
30 | this.primary = primary; | |
31 | this.secondary = secondary; | |
32 | } | |
33 | ||
34 | @Override | |
35 | protected void updateFrame(LedFrame frame, long time, int count) { | |
36 | for (int i = 0; i < config.leds.getCount(); i++) { | |
37 | double x = frame.xOf(i); | |
38 | double y = frame.yOf(i); | |
39 | double v = Math.pow(Math.min(1, Math.max(0, noise.getr(0.0, 1.0, 1, x, y, time / 7000.0))), 1.5); | |
40 | frame.setLedColor(i, primary.interpolate(secondary, v)); | |
41 | } | |
42 | } | |
43 | } |