X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FAmbientMode.java;h=ae223f1ac44c3c5ce86220e8113baa41e9250b3f;hb=2e308eba19d2ecdc077fbd3b2952425422a5a665;hp=51cb1e693d9903f215c513eb21ffc139e1982114;hpb=8aea44b5a5b9d56b600146ab305dfeef932772bd;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/AmbientMode.java b/src/kaka/cakelight/AmbientMode.java index 51cb1e6..ae223f1 100644 --- a/src/kaka/cakelight/AmbientMode.java +++ b/src/kaka/cakelight/AmbientMode.java @@ -1,8 +1,17 @@ package kaka.cakelight; +import kaka.cakelight.util.SimplexNoise3D; + public class AmbientMode extends Mode { // TODO split into DynamicAmbient and StaticAmbient? private Thread thread; // TODO move to a dynamic sub class private Configuration config; + private int type = 0; + + public AmbientMode(String[] args) { + if (args.length > 0) { + type = Integer.parseInt(args[0]); + } + } @Override public void enter(Configuration config) { @@ -26,7 +35,7 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St updateFrame(frame, System.currentTimeMillis() - start, index); updateWithFrame(frame); index = (index + 1) % config.leds.getCount(); - Thread.sleep(0); + Thread.sleep(20); } } catch (InterruptedException e) { } @@ -45,10 +54,31 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St * @param count Goes from 0 to number of LEDs - 1 */ private void updateFrame(LedFrame frame, long time, int count) { - for (int i = 0; i < config.leds.getCount(); i++) { - double r = Math.sin(2 * i * Math.PI / config.leds.getCount() + time * 0.001) * 0.5 + 0.5; - double g = Math.cos(2 * i * Math.PI / config.leds.getCount() + time * 0.002) * 0.5 + 0.5; - frame.setLedColor(i, Color.rgb(r, g, 0)); + if (type == 0) { + for (int i = 0; i < config.leds.getCount(); i++) { + double r = Math.sin(2 * i * Math.PI / config.leds.getCount() + time * 0.001) * 0.5 + 0.5; + double g = Math.cos(2 * i * Math.PI / config.leds.getCount() + time * 0.002) * 0.5 + 0.5; + frame.setLedColor(i, Color.rgb(r, g, 0)); + } + } else if (type == 1) { + for (int i = 0; i < config.leds.getCount(); i++) { + double x = frame.xOf(i); + double y = frame.yOf(i); + double g = Math.min(1, Math.max(0, noise.getr(-0.5, 0.5, 0.5, x, y, time / 5000.0))); + double b = Math.pow(Math.min(1, Math.max(0, noise.getr(0, 0.9, 1, x, y, time / 7000.0))), 2); + frame.setLedColor(i, Color.rgb(0, g, b)); + } + } else if (type == 2) { + int ledCount = config.leds.getCount(); + double hueOffset = time * 0.00001; + double hueLength = 1.0 / 6; + for (int i = 0; i < config.leds.getCount(); i++) { + double ledOffset = (i + (hueOffset * ledCount)) % ledCount; + double value = Math.abs((ledOffset * 2 - ledCount) / ledCount); // 1 to 0 to 1 + frame.setLedColor(i, Color.hsv(value * hueLength + hueOffset, 1, 1)); + } } } + + private SimplexNoise3D noise = new SimplexNoise3D(0); }