Skip to content

Instantly share code, notes, and snippets.

@isoraqathedh
Created December 10, 2015 15:30
Show Gist options
  • Save isoraqathedh/2e1523894e5ac83836e6 to your computer and use it in GitHub Desktop.
Save isoraqathedh/2e1523894e5ac83836e6 to your computer and use it in GitHub Desktop.
A rewrite of the plot generator.
var objvocab = {// Data object
"FIRST": [
"The average member of this race <build> and <height>. "
+ "They <epidermis>. "
+ "They have <feature>. "
+ " <wardrobe>. "
+ " <theylive> <environment>. "
+ " <personality> <trivia>."],
"build": [
"has a delicate build",
"has a slender build",
"has a stocky build",
"has a build similar to that of humans"],
"height": [
"is extremely tall",
"is quite tall",
"is a little taller than humans on average",
"is extremely short",
"is quite short",
"is a little shorter than humans on average",
"is around the same height as the average human"],
"epidermis": [
"have <complexions-human> skin and <hair>",
"have <complexions-human> skin and <hair-human>",
"have <complexions> and <hair>",
"have <deccolors> skin and <hair>",
"have skin covered in <deccolors> scales"],
"complexions": [
"<complexions-unwild> skin",
"<complexions-human> skin",
"<deccolors> skin"],
"hair": [
"are completely hairless",
"are completely hairless",
"are completely hairless",
"are covered with <haircolor> hair",
"have <haircolor> hair",
"have <haircolor> hair",
"have <haircolor> hair",
"have <haircolor> hair",
"have <haircolor> hair"],
"hair-human": [
"are completely hairless",
"are covered with <haircolor-human> hair",
"have <haircolor-human> hair"],
"haircolor": ["<haircolor-human>", "<deccolors>"],
"haircolor-human": [
"black",
"black to brown",
"blond",
"blond to brown",
"brown",
"red",
"red to brown",
"red to blond",
"white",
"white to blond"],
"complexions-unwild": [
"<shade-g><tint> gray",
"<shade-g><tint>",
"<shade-un-2>green",
"<shade-un-2>blue",
"<shade-g>grayish <grayish>",
"<shade-nv>brownish <brownish>"],
"complexions-human" : [
"brown",
"dark",
"dark brown",
"light to medium brown",
"medium brown",
"medium to dark brown",
"fair to dark brown",
"pale to dark brown",
"fair",
"pale",
"fair to pale"],
"feature": [
"<featureMarkings> and <featureEyes>",
"<featureEyes>",
"<featureEars> and <featureEyes>",
"<featureEars>, <featureMarkings>, and <featureEyes>",
"<featureMarkings>, <featureFace>, and <featureEyes>",
"<featureFace> and <featureEyes>",
"<featureEars>, <featureFace>, and <featureEyes>",
"<featureEars>, <featureMarkings>, <featureFace>, and <featureEyes>",
"<featureMarkings> and facial features "
+ "that put you in mind of <animal>",
"<featureMarkings>, <featureEyes-2>,"
+ " and facial features that put you in mind of <animal>",
"<featureEyes-2> and facial features that put you in mind of <animal>"],
"animal": [
"a cat", "a dog", "a rabbit", "a moose", "a seal", "an iguana",
"a snake", "a deer", "a rat", "a mouse", "a lizard", "a wolf",
"a monkey", "a turtle", "a bird", "an owl", "a beetle", "a moth",
"a horned toad", "a spider", "a buffalo", "an antelope", "a frog"],
"featureMarkings": ["<Markings> on their <BodyPart>"],
"featureEars": [
"antennae rather than ears",
"cat-like ears",
"ears shaped like leaves",
"long, pointed ears",
"very large ears",
"very small ears"],
"featureEyes": [
"<eyecolor> eyes",
"<eyecolor> <eyetype> eyes",
"large, <eyecolor> eyes",
"small, <eyecolor> eyes"],
"featureEyes-2": ["<eyecolor> eyes"],
"eyetype": [
"cat-like", "fish-like", "bird-like", "insectoid", "octopus-like"],
"eyecolor" : ["<eyecolor-human>", "<deccolors>", "<metallic>"],
"eyecolor-human": ["black", "blue", "brown", "dark", "gray", "green"],
"Markings": [
"colorful markings",
"distinctive markings",
"<spotcritter>-like spots",
"<stripecritter>-like stripes"],
"spotcritter": ["leopard", "cheetah", "giraffe", "fawn", "jaguar"],
"stripecritter": ["tiger", "tabby", "okapi"],
"featureFace": ["<FaceFeature> on their <FacePart>"],
"FaceFeature": [
"small ridges",
"delicate ridges",
"extensive ridges",
"prominent ridges",
"ridges",
"small hornlike protrusions",
"hornlike protrusions",
"prominent hornlike protrusions"],
"FacePart": ["ears", "foreheads", "heads", "noses"],
"BodyPart": [
"faces",
"faces, necks, and bodies",
"arms and legs",
"bodies"],
"wardrobe": ["They wear <clothing>",
"They wear <clothing> and <accessories>"],
"clothing": [
"<clothingDesc> clothing",
"<clothingDesc> clothing that covers most of their bodies",
"<clothingDesc> clothing that covers the essentials",
"<clothingDesc> clothing that leaves very little to the imagination",
"<clothingDesc>, modest clothing",
"highly technological suits"],
"clothingDesc": [
"colorful",
"drab",
"richly-decorated",
"simple"],
"accessories": [
"very little jewelry",
"a lot of jewelry",
"decorations that show their rank",
"<jewelryDesc> bracelets",
"<jewelryDesc> jewelry",
"<jewelryDesc> pendants",
"cybernetic implants"],
"jewelryDesc": [
"finely crafted",
"ostentatious",
"simple",
"tasteful"],
"theylive": [
"Their native habitat is",
"They are well-adapted to",
"They come from"],
"environment": [
"a cold climate",
"an aquatic environment",
"an extremely cold climate",
"a hot, dry climate",
"a temperate climate",
"a tropical environment",
"a warm climate"],
"trivia": [
"they are well-known for their <stuff>",
"their leaders are interested in learning about other peoples' <stuff>",
"many of them have expressed interest" +
" in learning about other peoples' <stuff>",
"<conquestystuff>"],
"conquestystuff": [
"at large they are out for conquest",
"many of their leaders have an aggressive expansionist policy",
"they have started several new colonies lately"],
"personality": [
"They are generally <trait> and",
"They tend to be <trait> and",
"They are often <trait> and",
"For the most part, their culture highly regards <trait2> and",
"Many of them place high importance on <trait2> and"],
"trait2": [
"caution",
"curiosity",
"intellectualism",
"loyalty",
"patriotism",
"tenacity",
"tradition"],
"trait": [
"cautious", "friendly", "intellectual", "mystical", "optimistic",
"pessimistic", "peaceful", "playful", "religious", "warlike",
"xenophobic"],
"stuff": [
"advances in medicine",
"art",
"contributions to science",
"cuisine",
"literature",
"music",
"philosophies"],
"deccolors": ["<warmcolor>", "<coolcolor>", "<gradient>", "<bw>"],
"mostlycoolend": [
"and <mbwwc>",
"and <mbwwc>",
"<warmcolor>, and <bw>",
"<metallic>, and <bw>"],
"gradient": [
"<shade-un>red-to-yellow",
"<shade-un>red-to-brown",
"<shade-un>red-to-orange",
"<shade-un>orange-to-yellow",
"<shade-un>orange-to-brown",
"<shade-un>magenta-to-pink",
"<shade-un>magenta-to-brown",
"<shade-un>magenta-to-orange",
"<shade-un>yellow-to-green",
"<shade-un>yellow-to-blue",
"<shade-un-2>green-to-turquoise",
"<shade-un-2>green-to-blue",
"<shade-un-2>turqoise-to-blue",
"<shade-un-2>blue-to-indigo",
"<shade-un-2>blue-to-purple",
"<shade-un-2>indigo-to-purple",
"<shade-un>brown"],
"warmcolor": [
"<shade-nv>brown",
"magenta",
"<shade-nl>red",
"<shade-nl>red",
"<shade>pink",
"<shade-nd>yellow",
"<shade-nd>yellow",
"<shade-nd>orange"],
"coolcolor": [
"<shade>aqua",
"<shade>green",
"<shade>green",
"<shade>blue",
"<shade>blue",
"<shade>blue",
"<shade>purple",
"<shade>purple",
"<shade>turquoise"],
"metallic": ["brass", "copper", "gold", "silver"],
"grayish": ["green", "blue", "purple", "indigo", "turquoise", "brown"],
"brownish": ["red", "orange"],
"bw": ["black", "<shade-g>gray", "<shade-g><tint> gray", "white"],
"mbw": ["<metallic>", "<bw>"],
"mbwcc": ["<metallic>", "<bw>", "<coolcolor>"],
"mbwwc": ["<metallic>", "<bw>", "<warmcolor>"],
"shade": ["variating ", "light ", "vivid ", "dark ", "muted ", "drab ",
""],
"shade-g": ["variating ", "light ", "dark ", ""],
"tint": ["greenish", "bluish", "pinkish", "purplish", "tealish"],
"shade-nl": ["variating ", "dark ", "vivid ", "muted ", "drab ", ""],
"shade-nd": ["variating ", "pastel ", "vivid ", "muted ", "drab ", ""],
"shade-nv": ["variating ", "light ", "dark ", "rich ",
"muted ", "drab ", ""],
"shade-un": ["variating ", "gradiating ", "muted ", "drab ", ""],
"shade-un-2": ["<shade-un>", "<shade>"],
"THIRD": [""]};
// In order for the plot generator to know what to expand,
// you need to feed it objvocab or aVocab.
// it will be able to figure out which one you used automatically.
plotGenerator.feedData(objvocab);
// This can be left alone.
function GenPlot() {
document.GENFORM.STORY.value = plotGenerator.expandAllVariables("<FIRST>");}
var plotGenerator = {
// This object holds all the functions and data
// required to process the input string.
// it can be separated out to a second file.
dataObj: {},
dataArr: [],
dataVersion: "",
// ------
feedData: function(list) {
// Feeds a list written elsewhere into the object.
// Automatically decides whether or not it is an old-style array
// or an associative array/object.
// updates the data variables above.
if (list instanceof Array) { // is an array
plotGenerator.dataArr = list;
plotGenerator.dataVersion = "array";}
else { // is an object
plotGenerator.dataObj = list;
plotGenerator.dataVersion = "object";}},
randomEntry: function(array) {
// Returns a random element in an array.
return array[Math.floor(Math.random() * array.length)];},
makeErrorOutput: function(variableName) {
// function to insert into output string if variable is not found.
return "[Variable " + variableName
+ " not defined – contact developer!]";},
expandVariable: function(variableName) {
if (plotGenerator.dataVersion === "array") { // Array version
for (var i in plotGenerator.dataArr) {
if (aVocab[i][0] === variableName) {
return plotGenerator.randomEntry(
plotGenerator.dataArr[i][1]);}}
// Fallthrough case
return plotGenerator.makeErrorOutput(variableName);}
else { // object version
if (plotGenerator.dataObj.hasOwnProperty(variableName)) {
return plotGenerator.randomEntry(
plotGenerator.dataObj[variableName]);}
else { // Fallthrough case
return plotGenerator.makeErrorOutput(variableName);}}},
expandAllVariables: function(string) {
var matches = "";
var variablePattern = /<([^<>]+)>/;
// ^ Regex pattern matching variables of the form <FOO>.
while (variablePattern.test(string)) { // some variables still found
matches = variablePattern.exec(string);
string = string.replace(matches[0],
plotGenerator.expandVariable(matches[1]));}
return string;}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment