From 8aea44b5a5b9d56b600146ab305dfeef932772bd Mon Sep 17 00:00:00 2001
From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= <tomas.wenstrom@gmail.com>
Date: Sun, 23 Apr 2017 19:25:22 +0200
Subject: [PATCH] Made the ambient mode nicer

---
 src/kaka/cakelight/AmbientMode.java | 22 +++++-----------------
 src/kaka/cakelight/Color.java       |  4 ++++
 2 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/src/kaka/cakelight/AmbientMode.java b/src/kaka/cakelight/AmbientMode.java
index 528a1c3..51cb1e6 100644
--- a/src/kaka/cakelight/AmbientMode.java
+++ b/src/kaka/cakelight/AmbientMode.java
@@ -7,17 +7,6 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St
     @Override
     public void enter(Configuration config) {
         this.config = config;
-//        LedFrame frame = LedFrame.from(config);
-//        frame.fillColor(255, 0, 128);
-//        frame.setLedColor(0, Color.rgb(255, 0, 0));
-//        frame.setLedColor(1, Color.rgb(0, 255, 0));
-//        frame.setLedColor(2, Color.rgb(0, 0, 255));
-//        for (int i = 0; i < config.leds.getCount(); i++) {
-////            int v = 255 * i / config.leds.getCount();
-//            int v = 60 * (i % 3);
-//            frame.setLedColor(i, Color.rgb(v, v, v));
-//        }
-//        frameListener.accept(frame);
         startThread();
     }
 
@@ -56,11 +45,10 @@ 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) {
-        frame.setLedColor(count, Color.rgb(255, 0, 0));
-        frame.setLedColor((count + 1) % config.leds.getCount(), Color.rgb(0, 255, 0));
-        frame.setLedColor((count + 2) % config.leds.getCount(), Color.rgb(0, 0, 255));
-//        for (int i = 0; i < config.leds.getCount(); i++) {
-//
-//        }
+        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));
+        }
     }
 }
diff --git a/src/kaka/cakelight/Color.java b/src/kaka/cakelight/Color.java
index ba85866..da09127 100644
--- a/src/kaka/cakelight/Color.java
+++ b/src/kaka/cakelight/Color.java
@@ -3,6 +3,10 @@ package kaka.cakelight;
 public class Color {
     private int r, g, b;
 
+    public static Color rgb(double r, double g, double b) {
+        return rgb((int)(255 * r), (int)(255 * g), (int)(255 * b));
+    }
+
     public static Color rgb(int r, int g, int b) {
         Color c = new Color();
         c.r = r;
-- 
2.11.0