Advertisement
Guest User

Untitled

a guest
May 26th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Random Generator</title>
  5. <script type="text/javascript">
  6. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7. // this is a completely self-contained random generator,
  8. // implemented in HTML and JavaScript.
  9. //
  10. // to create a new random generator, simply copy this file
  11. // and change the content of the gen_data array.
  12. //
  13. // the primary key of the gen_data array must be named 'main'.
  14. // to increase the number of random things generated at a time,
  15. // increase the number of rows of the output textarea.
  16. //
  17. // written and released to the public domain by drow [drow@bin.sh]
  18. // http://creativecommons.org/publicdomain/zero/1.0/
  19.  
  20. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  21. // json format
  22. // http://en.wikipedia.org/wiki/JSON
  23.  
  24. var gen_data = {};
  25.  
  26. gen_data['main'] = [
  27. '{firstsentence} {secondsentence}.'
  28. ];
  29. gen_data['firstsentence'] = [
  30. 'the {placenoun} is {placeadjed} by {treeadj}, {dark} {trees} that twist and turn unnaturally.',
  31. 'Massive {trees}, {treeadj} with {treeadj2} {branches}, {placeadj} the {area}, creating an unusually thick {placenoun}.',
  32. 'Twisting unnaturally, small growths of {branches} twine together to form massive {trees} that stretch high overhead.',
  33. 'Slick and {moss} mosses coat the outer layers of unnaturally twisting tree trunks that shoot high into the air.',
  34. '{dark} {treeadj2} {branches} loom overhead, {placenoun} {placeadjed} by {trees}.'
  35. ];
  36. gen_data['secondsentence'] = [
  37. 'Extending to great heights, these {treeadj} trunks are slicked with mosses, their bark {moss} and {treeadj2}.',
  38. 'The {branches} twist and turn unnaturally, reaching out to ensnare any hapless passers-by. Reaching towards the sky, the massive trunks are slickened with {moss} mosses.',
  39. '{treeadj} and {treeadj2}, the trunks of these silent sentinels are moss slickened and deformed.',
  40. 'The {placenoun} is {dark}, the {branches} reaching out at odd angles to snare at loose clothing or skin.'
  41. ];
  42. gen_data['placenoun'] = [
  43. 'area', 'forest', 'woods', 'woodland', 'timberland', 'thicket', 'wilderness', 'mirk'
  44. ];
  45. gen_data['placeadjed'] = [
  46. 'dominated', 'overseen', 'ringed', 'enclosed'
  47. ];
  48. gen_data['placeadj'] = [
  49. 'dominate', 'oversee', 'ring', 'suround'
  50. ];
  51. gen_data['treeadj'] = [
  52. 'tall', 'overgrown', 'giant', 'towering', 'twisted', 'battered'
  53. ];
  54. gen_data['treeadj2'] = [
  55. 'split', 'cracked', 'scarred', 'faded', 'rough', 'thick', 'hardened', 'knotted'
  56. ];
  57. gen_data['dark'] = [
  58. 'dark', 'dim', 'shadowed'
  59. ];
  60. gen_data['trees'] = [
  61. 'trees', 'oaks'
  62. ];
  63. gen_data['branches'] = [
  64. 'branches', 'boughs', 'limbs'
  65. ];
  66. gen_data['moss'] = [
  67. 'damp', 'rotting', 'dark', 'thin', 'crumbling'
  68. ];
  69. /*
  70. gen_data['gender'] = [
  71. 'male', 'female'
  72. ];
  73. gen_data['race'] = {
  74. '1-3': 'human',
  75. '4-5': 'dwarf',
  76. '6': 'elf'
  77. };
  78. gen_data['armor'] = {
  79. '01-50': 'leather armor',
  80. '51-90': 'chainmail',
  81. '91-00': 'plate armor'
  82. };
  83. gen_data['weapon'] = [
  84. '{melee_weapon}',
  85. '{melee_weapon} and a shield',
  86. 'twin blades',
  87. '{ranged_weapon}'
  88. ];
  89. gen_data['melee_weapon'] = [
  90. 'a battleaxe', 'a mace', 'a spear', 'a sword'
  91. ];
  92. gen_data['ranged_weapon'] = [
  93. 'a longbow and arrows', 'a heavy crossbow'
  94. ];
  95. */
  96.  
  97. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  98. </script>
  99. </head>
  100. <body>
  101. <form method="get" onsubmit="return false;">
  102. <p><textarea id="output" cols="100" rows="10" readonly></textarea></p>
  103. <p><input type="button" value="Generate" onclick="more_random(); correct();" /></p>
  104. <p><input type="button" value="Correct" onclick="correct();" /></p>
  105. </form>
  106. <script type="text/javascript">
  107. function more_random() {
  108. var a=document.getElementById("output"),b=parseInt(1);
  109. if(b<1)b=1;b=generate_list("main",b);
  110. a.value=b.join("\n")
  111. }
  112. function generate_text(a){
  113. if(a=gen_data[a])
  114. if(a=select_from(a))
  115. return expand_tokens(a);
  116. return""}
  117. function generate_list(a,b){
  118. var c=[],d;
  119. for(d=0;d<b;d++)c.push(generate_text(a));
  120. return c}
  121. function select_from(a){
  122. return a.constructor==Array?select_from_array(a):select_from_table(a)}
  123. function select_from_array(a){
  124. return a[Math.floor(Math.random()*a.length)]}
  125. function select_from_table(a){
  126. var b;
  127. if(b=scale_table(a)){b=Math.floor(Math.random()*b)+1;
  128. var c;
  129. for(c in a){var d=key_range(c);
  130. if(b>=d[0]&&b<=d[1])return a[c]}}return""}
  131. function key_range(a){
  132. var b;
  133. return(b=/(\d+)-00/.exec(a))?[parseInt(b[1]),100]:(b=/(\d+)-(\d+)/.exec(a))?[parseInt(b[1]),parseInt(b[2])]:a=="00"?[100,100]:[parseInt(a),parseInt(a)]}
  134. function expand_tokens(a){
  135. for(
  136. var b;
  137. b=/{(\w+)}/.exec(a);)
  138. {b=b[1];
  139. var c;
  140. a=(c=generate_text(b))?a.replace("{"+b+"}",c):a.replace("{"+b+"}",b)}return a}
  141. more_random();
  142.  
  143. function correct() {
  144. str = document.getElementById("output").value;
  145. str = str.charAt(0).toUpperCase() +str.slice(1);
  146. str = str.replace(/.+?[\.\?\!](\s|$)/g, function (txt){
  147. return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  148. });
  149. document.getElementById("output").value = str
  150. }
  151.  
  152.  
  153. </script>
  154. </body>
  155. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement