Skip to content

Commit

Permalink
Add --horizontal millipede
Browse files Browse the repository at this point in the history
  • Loading branch information
tusbar committed Aug 1, 2015
1 parent 9132e78 commit be22097
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 6 deletions.
19 changes: 14 additions & 5 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ program
.option('-s, --size <value>', 'size of the millipede', int(true), 20)
.option('-p, --position <value>', 'move the millipede forward, make it move!', int(true))
.option('-r, --reverse', 'reverse the millipede')
.option('-h, --horizontal', 'rotate the millipede, and display it horizontally')
.option('-t, --top <value>', 'add <value> lines of top padding', int(true))
.option('-l, --left <value>', 'add <value> lines of left padding', int(true))
.option('-a, --animate', 'animate the millipede')
Expand All @@ -37,20 +38,28 @@ program
try {
var me = millipede(program.size, {
reverse: program.reverse,
horizontal: program.horizontal,
position: program.position,
top: program.top,
left: program.left
});

if (program.fullSize) {
// The millipede current size will be overriden
me.size = windowInfo[1] - 2;
if (me.horizontal) {
me.size = Math.floor(windowInfo[0] / 2) - 2;
}
else {
me.size = windowInfo[1] - 2;
}
}

if (program.center) {
// This centers the millipede, by default
// But you can always add more left padding!
me.left += Math.floor((windowInfo[0] - me.getLargestBodyPart()) / 2);
if (me.horizontal) {
me.top += Math.floor((windowInfo[1] - me.getLargestBodyPart()) / 2);
}
else {
me.left += Math.floor((windowInfo[0] - me.getLargestBodyPart()) / 2);
}
}

if (program.animate) {
Expand Down
71 changes: 70 additions & 1 deletion lib/millipede.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,66 @@ Millipede.prototype._getVertical = function () {
return this._getVerticalHead() + '\n' + this._getVerticalBody();
};

/**
* Return the horizontal `Millipede` as a string
*
* @return {String} representing the horizontal `Millipede`
* @private
*/

Millipede.prototype._getHorizontal = function () {
var lines = new Array(this.getLargestBodyPart()).join('.').split('.');
var position;
var index;

if (this.reverse) {
position = this._P[(this.position) % this._PL].length;

for (index = 0; index < position; index++) {
lines[index] = ' ';
}

lines[position] += '══ ';
lines[position + 1] += ' ⊙ ';
lines[position + 2] += ' ⊙ ';
lines[position + 3] += '══ ';

for (index = position + 4; index < lines.length; index++) {
lines[index] = ' ';
}
}

for (index = 0; index < this.size; index++) {
position = this._P[this._LP - (this.size - 1 - index + this.position) % this._PL].length;

if (this.reverse) {
position = this._P[(index + this.position) % this._PL].length;
}

for (var p = 0; p < position; p++) {
lines[p] += ' ';
}

lines[position] += '╔ ';
lines[position + 1] += '﹋';
lines[position + 2] += '﹏';
lines[position + 3] += '╚ ';

for (p = position + 4; p < lines.length; p++) {
lines[p] += ' ';
}
}

if (!this.reverse) {
lines[position] += ' ══';
lines[position + 1] += ' ⊙';
lines[position + 2] += ' ⊙';
lines[position + 3] += ' ══';
}

return lines.join('\n');
};

/**
* Validate `Millipede` settings
*
Expand Down Expand Up @@ -182,6 +242,10 @@ Millipede.prototype.getLargestBodyPart = function () {
return padding.length;
}));

if (this.horizontal) {
return largest + 4;
}

if (this.reverse) {
return largest + '╔═(███)═╗'.length;
}
Expand All @@ -204,7 +268,12 @@ Millipede.prototype.toString = function () {
output += new Array(this.top + 1).join('\n');
}

output += this._getVertical();
if (this.horizontal) {
output += this._getHorizontal();
}
else {
output += this._getVertical();
}

return output;
};
Expand Down

0 comments on commit be22097

Please sign in to comment.