Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Random Generator</title>
- <script type="text/javascript">
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // this is a completely self-contained random generator,
- // implemented in HTML and JavaScript.
- //
- // to create a new random generator, simply copy this file
- // and change the content of the gen_data array.
- //
- // the primary key of the gen_data array must be named 'main'.
- // to increase the number of random things generated at a time,
- // increase the number of rows of the output textarea.
- //
- // written and released to the public domain by drow [drow@bin.sh]
- // http://creativecommons.org/publicdomain/zero/1.0/
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // json format
- // http://en.wikipedia.org/wiki/JSON
- var gen_data = {};
- gen_data['main'] = [
- '{firstsentence} {secondsentence}.'
- ];
- gen_data['firstsentence'] = [
- 'the {placenoun} is {placeadjed} by {treeadj}, {dark} {trees} that twist and turn unnaturally.',
- 'Massive {trees}, {treeadj} with {treeadj2} {branches}, {placeadj} the {area}, creating an unusually thick {placenoun}.',
- 'Twisting unnaturally, small growths of {branches} twine together to form massive {trees} that stretch high overhead.',
- 'Slick and {moss} mosses coat the outer layers of unnaturally twisting tree trunks that shoot high into the air.',
- '{dark} {treeadj2} {branches} loom overhead, {placenoun} {placeadjed} by {trees}.'
- ];
- gen_data['secondsentence'] = [
- 'Extending to great heights, these {treeadj} trunks are slicked with mosses, their bark {moss} and {treeadj2}.',
- '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.',
- '{treeadj} and {treeadj2}, the trunks of these silent sentinels are moss slickened and deformed.',
- 'The {placenoun} is {dark}, the {branches} reaching out at odd angles to snare at loose clothing or skin.'
- ];
- gen_data['placenoun'] = [
- 'area', 'forest', 'woods', 'woodland', 'timberland', 'thicket', 'wilderness', 'mirk'
- ];
- gen_data['placeadjed'] = [
- 'dominated', 'overseen', 'ringed', 'enclosed'
- ];
- gen_data['placeadj'] = [
- 'dominate', 'oversee', 'ring', 'suround'
- ];
- gen_data['treeadj'] = [
- 'tall', 'overgrown', 'giant', 'towering', 'twisted', 'battered'
- ];
- gen_data['treeadj2'] = [
- 'split', 'cracked', 'scarred', 'faded', 'rough', 'thick', 'hardened', 'knotted'
- ];
- gen_data['dark'] = [
- 'dark', 'dim', 'shadowed'
- ];
- gen_data['trees'] = [
- 'trees', 'oaks'
- ];
- gen_data['branches'] = [
- 'branches', 'boughs', 'limbs'
- ];
- gen_data['moss'] = [
- 'damp', 'rotting', 'dark', 'thin', 'crumbling'
- ];
- /*
- gen_data['gender'] = [
- 'male', 'female'
- ];
- gen_data['race'] = {
- '1-3': 'human',
- '4-5': 'dwarf',
- '6': 'elf'
- };
- gen_data['armor'] = {
- '01-50': 'leather armor',
- '51-90': 'chainmail',
- '91-00': 'plate armor'
- };
- gen_data['weapon'] = [
- '{melee_weapon}',
- '{melee_weapon} and a shield',
- 'twin blades',
- '{ranged_weapon}'
- ];
- gen_data['melee_weapon'] = [
- 'a battleaxe', 'a mace', 'a spear', 'a sword'
- ];
- gen_data['ranged_weapon'] = [
- 'a longbow and arrows', 'a heavy crossbow'
- ];
- */
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- </script>
- </head>
- <body>
- <form method="get" onsubmit="return false;">
- <p><textarea id="output" cols="100" rows="10" readonly></textarea></p>
- <p><input type="button" value="Generate" onclick="more_random(); correct();" /></p>
- <p><input type="button" value="Correct" onclick="correct();" /></p>
- </form>
- <script type="text/javascript">
- function more_random() {
- var a=document.getElementById("output"),b=parseInt(1);
- if(b<1)b=1;b=generate_list("main",b);
- a.value=b.join("\n")
- }
- function generate_text(a){
- if(a=gen_data[a])
- if(a=select_from(a))
- return expand_tokens(a);
- return""}
- function generate_list(a,b){
- var c=[],d;
- for(d=0;d<b;d++)c.push(generate_text(a));
- return c}
- function select_from(a){
- return a.constructor==Array?select_from_array(a):select_from_table(a)}
- function select_from_array(a){
- return a[Math.floor(Math.random()*a.length)]}
- function select_from_table(a){
- var b;
- if(b=scale_table(a)){b=Math.floor(Math.random()*b)+1;
- var c;
- for(c in a){var d=key_range(c);
- if(b>=d[0]&&b<=d[1])return a[c]}}return""}
- function key_range(a){
- var b;
- 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)]}
- function expand_tokens(a){
- for(
- var b;
- b=/{(\w+)}/.exec(a);)
- {b=b[1];
- var c;
- a=(c=generate_text(b))?a.replace("{"+b+"}",c):a.replace("{"+b+"}",b)}return a}
- more_random();
- function correct() {
- str = document.getElementById("output").value;
- str = str.charAt(0).toUpperCase() +str.slice(1);
- str = str.replace(/.+?[\.\?\!](\s|$)/g, function (txt){
- return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
- });
- document.getElementById("output").value = str
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement