git @ Cat's Eye Technologies Lexeduct / 5b5fcee
'chance' param on insert-,remove-chars. Support multi param in UI. Chris Pressey 6 years ago
3 changed file(s) with 34 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
6666 this.updateParametersPanel = function(slot, panel) {
6767 var parameters = transformer[slot.name].parameters;
6868 panel.innerHTML = ""; // delete any previous controls
69 for (var key in parameters) {
70 if (parameters.hasOwnProperty(key)) {
71 var desc = parameters[key][0];
72 var def = parameters[key][1];
73 var label = yoob.makeSpan(panel, key);
74 var input = yoob.makeTextInput(panel, 24, def);
75 slot.selectedParams[key] = def;
76 input.onchange = function() {
77 slot.selectedParams[key] = input.value;
78 if (liveMode) {
79 process();
80 }
81 }
82 yoob.makeLineBreak(panel);
69 for (var paramName in parameters) {
70 if (parameters.hasOwnProperty(paramName)) {
71 var desc = parameters[paramName][0];
72 var def = parameters[paramName][1];
73 this.makeParameterEditor(slot, panel, paramName, desc, def);
8374 }
8475 }
76 };
77
78 this.makeParameterEditor = function(slot, panel, paramName, desc, def) {
79 var label = yoob.makeSpan(panel, paramName);
80 var input = yoob.makeTextInput(panel, 24, def);
81 slot.selectedParams[paramName] = def;
82 input.onchange = function() {
83 slot.selectedParams[paramName] = input.value;
84 if (liveMode) {
85 process();
86 }
87 }
88 yoob.makeLineBreak(panel);
8589 };
8690
8791 this.makeTransformerSlot = function(container, index) {
00 module.exports = {
11 makeTransformer: function(cfg) {
2 cfg.chance = parseInt(cfg.chance || "100", 10);
23 return function(str, state) {
34 var s = "";
45 for (var i = 0; i < str.length; i++) {
5 var c = cfg.chars.charAt(Math.floor(Math.random() * cfg.chars.length));
6 s += str.charAt(i) + c;
6 s += str.charAt(i);
7 if (Math.floor(Math.random() * 100) < cfg.chance) {
8 s += cfg.chars.charAt(
9 Math.floor(Math.random() * cfg.chars.length)
10 );
11 }
712 }
813 return s;
914 };
1015 },
1116 parameters: {
12 'chars': ["The set of characters to select from", ""]
17 'chars': ["The set of characters to select from", ""],
18 'chance': ["Probability (0-100) of applying to any individual character", "100"]
1319 },
1420 description: "Insert a randomly-selected character after each character"
1521 };
00 module.exports = {
11 makeTransformer: function(cfg) {
2 cfg.chance = parseInt(cfg.chance || "100", 10);
23 return function(str, state) {
34 var s = "";
45 for (var i = 0; i < str.length; i++) {
56 var c = str.charAt(i);
6 if (cfg.chars.indexOf(c) === -1) {
7 s += c;
7 if (cfg.chars.indexOf(c) > -1 &&
8 Math.floor(Math.random() * 100) < cfg.chance) {
9 continue;
810 }
11 s += c;
912 }
1013 return s;
1114 };
1215 },
1316 parameters: {
14 'chars': ["The set of characters to remove", ""]
17 'chars': ["The set of characters to remove", ""],
18 'chance': ["Probability (0-100) of applying to any individual character", "100"]
1519 },
1620 description: "Remove all occurrences of the specified characters"
1721 };