]> git.r.bdr.sh - rbdr/heart/commitdiff
Merge branch 'release/1.0.1'
authorBen Beltran <redacted>
Thu, 16 Feb 2017 07:22:26 +0000 (01:22 -0600)
committerBen Beltran <redacted>
Thu, 16 Feb 2017 07:22:26 +0000 (01:22 -0600)
CHANGELOG.md
js/app.js
js/lib/heart_renderer.js
package.json

index 26b98880cc40f67edccdd892eba02f1b43dc7b36..4098b59499229f5660a8ea1056e1eb5ece73715a 100644 (file)
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/)
 and this project adheres to [Semantic Versioning](http://semver.org/).
 
+## [1.0.1] - 2017-02-16
+### Added
+- Add mouse following
+- Fix README links
+
 ## 1.0.0 - 2016-11-10
 ### Added
 - Basic configuration for jsdoc
@@ -13,4 +18,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 - This changelog
 - Heart Renderer
 
-[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/master...develop
+[Unreleased]: https://github.com/rbdr/heart/compare/master...develop
+[1.0.1]: https://github.com/rbdr/heart/compare/1.0.0...1.0.1
index 12065b2c704e38320730442fee0d41a611237eb8..63990dc1bbca0e80e7cabea851b2f39b35503a34 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -15,6 +15,8 @@
     heartRenderer.activate();
 
     window.addEventListener('resize', heartRenderer.resize.bind(heartRenderer));
+    window.addEventListener('blur', heartRenderer.stopFollowingMouse.bind(heartRenderer));
+    window.addEventListener('focus', heartRenderer.startFollowingMouse.bind(heartRenderer));
 
     /**
      * Exported global object. This will contain the instance of the heart
index fd4adf6452e511e7090b1b0e7519dd467ef6829b..78ca182e96f4a38c061685ea66c255a488dc154c 100644 (file)
@@ -51,6 +51,8 @@
        */
       this.heartSize = 50;
 
+      this._following = null; // The status of mouse follow.
+      this._center = null;
       this._animating = false; // The status of the animation.
       this._previousFrameTime = Date.now(); // The timestamp of the last frame for fps control
       this._currentColor = { // The current color that will be painted
@@ -59,6 +61,8 @@
         green: 50
       };
 
+      this.startFollowingMouse();
+
       Object.assign(this, config);
     }
 
@@ -82,7 +86,6 @@
      * @memberof HeartRenderer
      * @function render
      * @instance
-     * @param {HTMLElement} element the element where we will attach our canvas
      */
     resize() {
 
       }
     }
 
+    /**
+     * Follows the mouse
+     *
+     * @memberof HeartRenderer
+     * @function startFollowingMouse
+     * @instance
+     */
+    startFollowingMouse() {
+
+      if (!this._following) {
+        console.log('Start Following Mouse');
+        this._following = this._setCenterFromMouse.bind(this);
+        this.canvas.addEventListener('mousemove', this._following);
+      }
+    }
+
+    /**
+     * Stop following the mouse
+     *
+     * @memberof HeartRenderer
+     * @function stopFollowingMouse
+     * @instance
+     */
+    stopFollowingMouse() {
+
+      if (this._following) {
+        console.log('Stop Following Mouse');
+        this.canvas.removeEventListener('mouseover', this._following);
+        this._following = null;
+        this._center = null;
+      }
+    }
+
     /**
      * Gets the context from the current canvas and starts the animation process
      *
 
       const heartSize = Math.round(referenceDimension * this.heartSize * .01);
       const radius = heartSize / 2;
-      const canvasCenterX = Math.round(canvasWidth / 2);
-      const canvasCenterY = Math.round(canvasHeight / 2);
+      let canvasCenterX = this._center ? this._center.x : Math.round(canvasWidth / 2);
+      let canvasCenterY = this._center ? this._center.y : Math.round(canvasHeight / 2);
       const centerX = -radius;
       const centerY = -radius;
 
 
       context.setTransform(1, 0, 0, 1, 0, 0);
     }
+
+    // Sets the center from mouse
+    _setCenterFromMouse (event) {
+      this._center = this._center || {};
+
+      console.log('tracking');
+
+      this._center.x = event.offsetX;
+      this._center.y = event.offsetY;
+    }
   };
 
 
index 36e8f3dbfade86973d1699e65506e8d2ee4d2141..7197e410584d951fc180ae2fcd3bd7659a1609d9 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "heart",
-  "version": "1.0.0",
+  "version": "1.0.1",
   "description": "The heart",
   "main": "index.js",
   "scripts": {