From 815bf32c3c5567c061f1cd78583ed2a42df94e16 Mon Sep 17 00:00:00 2001 From: Victor Hugo Brito Fernandes Date: Tue, 12 Dec 2017 16:28:07 -0200 Subject: [PATCH 1/4] added christmas tree patroling command --- commands/christmaspatrol.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 commands/christmaspatrol.js diff --git a/commands/christmaspatrol.js b/commands/christmaspatrol.js new file mode 100644 index 0000000..f1695da --- /dev/null +++ b/commands/christmaspatrol.js @@ -0,0 +1,22 @@ +module.exports = function (bb8,options) { + var radius = options.radius; //mm + var distance = 2*Math.PI*radius; + var colors = ["red","green"]; + var i = 0; + return setInterval(function() { + var direction = 30; + bb8.roll(Math.floor(distance/12),direction*i); + var chosen = (function(){ + if (Math.random() > 0.5) { + return 1; + } else { + return 0; + } + })(); + bb8.color(colors[chosen]); + i++; + if (i>11) { + i = 0; + } + }, 500); +}; From 0988988397325c294dda762ff3511b5a3b815623 Mon Sep 17 00:00:00 2001 From: Victor Hugo Brito Fernandes Date: Mon, 9 Apr 2018 22:06:03 -0300 Subject: [PATCH 2/4] added as a contributer on readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index be14ee5..75e9e77 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,7 @@ bb8.executeCustomCommand(filePath, {colour: '#000000'}); * [@citypaul](http://twitter.com/paulhammond) * [@sud-puth](http://twitter.com/sud_) * [@saraford](http://twitter.com/saraford) +* [@veaga](http://twitter.com/veaga) # Want to contribute? From 0c2b8dac8ff61b3791753f26f7f090045b5ef421 Mon Sep 17 00:00:00 2001 From: Victor Hugo Brito Fernandes Date: Mon, 9 Apr 2018 22:20:46 -0300 Subject: [PATCH 3/4] fixing counter name and adding lodash to color sampler --- commands/christmaspatrol.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/commands/christmaspatrol.js b/commands/christmaspatrol.js index f1695da..60ff223 100644 --- a/commands/christmaspatrol.js +++ b/commands/christmaspatrol.js @@ -1,22 +1,15 @@ module.exports = function (bb8,options) { - var radius = options.radius; //mm - var distance = 2*Math.PI*radius; - var colors = ["red","green"]; - var i = 0; - return setInterval(function() { + var radius = options.radius; //mm + var distance = 2*Math.PI*radius; + var colors = ["red","green"]; + var angle_counter = 0; var direction = 30; - bb8.roll(Math.floor(distance/12),direction*i); - var chosen = (function(){ - if (Math.random() > 0.5) { - return 1; - } else { - return 0; - } - })(); - bb8.color(colors[chosen]); - i++; - if (i>11) { - i = 0; - } - }, 500); + return setInterval(function() { + bb8.roll(Math.floor(distance/12),direction*angle_counter); + bb8.color(_.sample(colors)); + angle_counter++; + if (angle_counter>11) { + angle_counter = 0; + } + }, 500); }; From 91caaba2945ccdd20f49d7a83b4fd3b33dac0777 Mon Sep 17 00:00:00 2001 From: Victor Hugo Brito Fernandes Date: Tue, 10 Apr 2018 10:27:23 -0300 Subject: [PATCH 4/4] added lodash requirement --- commands/christmaspatrol.js | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/christmaspatrol.js b/commands/christmaspatrol.js index 60ff223..40a94b8 100644 --- a/commands/christmaspatrol.js +++ b/commands/christmaspatrol.js @@ -1,3 +1,4 @@ +var _ = require('lodash') module.exports = function (bb8,options) { var radius = options.radius; //mm var distance = 2*Math.PI*radius;