Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var crypto = require('crypto');
- function sha1hexFromString(src){
- var sha1hash = crypto.createHash('sha1');
- sha1hash.update(src, 'binary');
- return sha1hash.digest('hex');
- }
- function arrayFromHexString(hexstr){
- var r = [];
- for(var i=0,j=hexstr.length; i<j; i++){
- r.push(parseInt(hexstr[i], 16));
- }
- return r;
- }
- function configFromArray(arr){
- var nodes = [];
- for(var i=8,j=arr.length; i<j; i+=2){
- nodes.push(arr[i] + arr[i+1]);
- }
- return {
- red: arr[0] * 16 + arr[4],
- green: arr[1] * 16 + arr[5],
- blue: arr[2] * 16 + arr[6],
- alpha: arr[3] * 16 + arr[7],
- nodes: nodes
- };
- }
- function svgFromConfig(config, width, height){
- width = width || config.width || 64;
- height = height || config.height || 64;
- var color = 'rgba(' + [config.red, config.green, config.blue, config.alpha].join(', ') + ')';
- var buf = [];
- var scaleX = width / 256;
- var scaleY = height / 256;
- buf.push('<svg width="'+width+'" height="'+height+'">');
- buf.push('<g transform="scale('+ scaleX + ',' + scaleY + ')">');
- var nodes = config.nodes;
- for(var i=0, j=nodes.length; i<j; i++){
- var size = nodes[i] * 2;
- var delta = 32 - nodes[i];
- var x = (Math.floor(i % 4) * 64) + delta;
- var y = (Math.floor(i / 4) * 64) + delta;
- buf.push('<rect width="'+ size + '" height="'+ size +'" fill="' + color + '" x="' + x + '" y="' + y + '">');
- buf.push('</rect>');
- }
- buf.push('</g>');
- buf.push('</svg>');
- return buf.join('\n');
- }
- // console.log(sha1hexFromString('hmm'));
- // console.log(arrayFromHexString(sha1hexFromString('hmm')));
- var candidates = [
- "a",
- "b",
- "c",
- "memo",
- "test",
- "foo",
- "memo1",
- "memo2",
- "memo3",
- "memo4",
- "memo5",
- "memo6",
- "memo7",
- "memo8",
- "memo9",
- "memo10",
- "memo11",
- "memo12",
- "memo13",
- "memo14",
- "memo15",
- "memo16",
- "memo17",
- "memo18",
- "memo19",
- "memo110"
- ];
- console.log("<table>");
- candidates.forEach(function(s){
- console.log("<tr>");
- console.log("<td>");
- console.log(s);
- console.log("</td>");
- console.log("<td>");
- console.log(
- svgFromConfig(
- configFromArray(
- arrayFromHexString(
- sha1hexFromString(s)))));
- console.log("</td>");
- console.log("<tr>");
- });
- console.log("</table>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement