+ this._updateColor(delta);
+ this._drawHeart(context, delta);
+ }
+
+ // Updates the current color
+ _updateColor(delta) {
+
+ 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;
+ }
+
+ // Draws a heart
+ _drawHeart(context, delta) {
+
+ const canvasHeight = this.canvas.height;
+ const canvasWidth = this.canvas.width;
+
+ const referenceDimension = canvasWidth < canvasHeight ? canvasWidth : canvasHeight;
+
+ this.heartSize += Math.sign(this._targetHeartSize - this.heartSize) * this._resizeSpeed;
+
+ const heartSize = Math.round(referenceDimension * this.heartSize * .01);
+ const radius = heartSize / 2;
+
+ if (!this._center) {
+ this._center = {};
+ this._center.x = Math.round(canvasWidth / 2);
+ this._center.y = Math.round(canvasHeight / 2);
+ }
+
+ const deltaY = this._targetCenter.y - this._center.y;
+ const deltaX = this._targetCenter.x - this._center.x;
+ const angle = Math.atan2(deltaY, deltaX);
+
+ // Move towards the target
+ this._center.x += Math.cos(angle) * this._trackingSpeed;
+ this._center.y += Math.sin(angle) * this._trackingSpeed;
+
+ const canvasCenterX = this._center.x;
+ const canvasCenterY = this._center.y;
+ const centerX = -radius;
+ const centerY = -radius;
+
+
+ // translate and rotate, adjusting for weight of the heart.
+ context.translate(canvasCenterX, canvasCenterY + radius / 4);
+ context.rotate(-45 * Math.PI / 180);