Skip to content

Commit

Permalink
Cleanup, v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
walsh9 committed Sep 1, 2014
1 parent 9f677c7 commit b220747
Show file tree
Hide file tree
Showing 15 changed files with 496 additions and 545 deletions.
5 changes: 2 additions & 3 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ module.exports = ->
/*! <%= package.name %> - v<%= package.version %> - <%= grunt.template.today('yyyy-mm-dd') %> \
** https://<%= package.homepage %> \
** Copyright (c) <%= grunt.template.today('yyyy') %> <%= package.author %>; Licensed under <%= package.license %> license. */\
\
"""

convert:
Expand Down Expand Up @@ -41,7 +40,7 @@ module.exports = ->
options:
js:
indentChar: " "
indentSize: 2
indentSize: 4

jshint:
dist: ['dist/asciibots.js', 'dist/jquery/asciibots.js']
Expand Down
230 changes: 110 additions & 120 deletions dist/asciibots.js
Original file line number Diff line number Diff line change
@@ -1,124 +1,114 @@
/*! asciibots.js - v0.9 - 2014-08-21
/*! asciibots.js - v1.0 - 2014-08-31
** https://walsh9.github.io/asciibots
** Copyright (c) 2014 Matthew Walsh; Licensed under MIT license. */

var Asciibots = (function() {

robots = {
"templates": {
"0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ",
"1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ",
"2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ",
"3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ",
"4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ",
"5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ",
"6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ",
"7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .",
"8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ",
"9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ",
"a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ",
"b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ",
"c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ",
"d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ",
"e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ",
"f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ "
},
"spareParts": {
"eyes": {
"0": "o o",
"1": "p q",
"2": "q p",
"3": "d b",
"4": "b d",
"5": "ooo",
"6": "[o]",
"7": "9 9",
"8": "6=6",
"9": "u u",
"a": "n n",
"b": "q q",
"c": "d d",
"d": "- -",
"e": "0 0",
"f": "O O"
},
"mouths": {
"0": "-",
"1": "=",
"2": "o",
"3": "O",
"4": "0",
"5": "#",
"6": "u",
"7": "v",
"8": "n",
"9": "r",
"a": "`",
"b": "^",
"c": "A",
"d": "@",
"e": "e",
"f": "E"
}
}
};

var idHelper = {

isValid: function(id, minlength, maxlength, radix) {
var range = "";
if (radix < 2 || radix > 36) {
throw "RangeError: radix must be an integer at least 2 and no greater than 36";
} else if (radix <= 10) {
range = "0-" + String(radix - 1);
} else {
range = "0-9a-" + (radix - 1).toString(radix);
}
var re = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$");
return (id && re.test(id.toLowerCase()));
},

random: function(length, radix) {
var id = "";
for (var i = length; i > 0; i--) {
id = id + Math.floor(Math.random() * radix).toString(radix);
}
return id;
}

};

function oneBot(id) {
var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""),
botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] +
botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] +
botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2];
if (botIdDigits.length >= 4) {
botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1);
}
if (botIdDigits.length >= 5) {
botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2);
}
return botString;
}

function replaceParts(id, botString, parts, x, y) {
lines = botString.split("\n");
newPart = parts[id];
lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length);
return lines.join("\n");
}

function botSplit(botString) {
var splitBot = [];
splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n";
splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n";
splitBot[2] = botString.split("\n").slice(5, 7).join("\n");
return splitBot;
}

return {
bot: oneBot
};

robots = {
"templates": {
"0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ",
"1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ",
"2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ",
"3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ",
"4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ",
"5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ",
"6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ",
"7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .",
"8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ",
"9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ",
"a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ",
"b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ",
"c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ",
"d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ",
"e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ",
"f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ "
},
"spareParts": {
"eyes": {
"0": "o o",
"1": "p q",
"2": "q p",
"3": "d b",
"4": "b d",
"5": "ooo",
"6": "[o]",
"7": "9 9",
"8": "6=6",
"9": "u u",
"a": "n n",
"b": "q q",
"c": "d d",
"d": "- -",
"e": "0 0",
"f": "O O"
},
"mouths": {
"0": "-",
"1": "=",
"2": "o",
"3": "O",
"4": "0",
"5": "#",
"6": "u",
"7": "v",
"8": "n",
"9": "r",
"a": "`",
"b": "^",
"c": "A",
"d": "@",
"e": "e",
"f": "E"
}
}
};
var idHelper = {
isValid: function(id, minlength, maxlength, radix) {
var range = "",
idPattern;
if (radix < 2 || radix > 36) {
throw new RangeError("radix must be an integer at least 2 and no greater than 36");
} else if (radix <= 10) {
range = "0-" + String(radix - 1);
} else {
range = "0-9a-" + (radix - 1).toString(radix);
}
idPattern = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$");
return (id && idPattern.test(id.toLowerCase()));
},
random: function(length, radix) {
var id = "";
for (var i = length; i > 0; i--) {
id = id + Math.floor(Math.random() * radix).toString(radix);
}
return id;
}
};
var oneBot = function(id) {
var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""),
botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] +
botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] +
botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2];
if (botIdDigits.length >= 4) {
botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1);
}
if (botIdDigits.length >= 5) {
botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2);
}
return botString;
};
var replaceParts = function(id, botString, parts, x, y) {
var lines = botString.split("\n"),
newPart = parts[id];
lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length);
return lines.join("\n");
};
var botSplit = function(botString) {
var splitBot = [];
splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n";
splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n";
splitBot[2] = botString.split("\n").slice(5, 7).join("\n");
return splitBot;
};
return {
bot: oneBot
};
})();
2 changes: 1 addition & 1 deletion dist/asciibots.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b220747

Please sign in to comment.