- this._currentColor.red = Math.round(this._currentColor.red + delta * kRedSpeed) % kColorIteratorLimit;
- this._currentColor.green = Math.round(this._currentColor.green + delta * kGreenSpeed) % kColorIteratorLimit;
- this._currentColor.blue = Math.round(this._currentColor.blue + delta * kBlueSpeed) % kColorIteratorLimit;
+ const red = this._updateColorComponent('red', delta);
+ const green = this._updateColorComponent('green', delta);
+ const blue = this._updateColorComponent('blue', delta);
+
+ console.log(red, green, blue);
+
+ this._currentColor.red = red;
+ this._currentColor.green = green;
+ this._currentColor.blue = blue;
+ }
+
+ // Updates a single color component.
+ _updateColorComponent(component, delta) {
+ let color = Math.round(this._currentColor[component] + (delta * this._colorSpeed[component] * this._colorDirection[component]));
+ if (color >= kColorIteratorLimit) {
+ this._colorDirection[component] = -1;
+ color = kColorIteratorLimit;
+ }
+
+ if (color <= 0) {
+ this._colorDirection[component] = 1;
+ color = 0;
+ }
+
+ return color;