6 thoughts on “The Shakespeare Insult Kit”

  1. Here is an example Java object that generates random insults. I thought it may be a fun way to learn a little bit of the Collections interface.

    Anyway, re-format code as desired. (r3dux: Done!)

    The object:

    package org.r3dux.misc;
     
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;
    import java.util.Random;
     
    public class GenerateInsult {
    	static Random wheel = new Random();
     
    	private static List adjectives = Arrays.asList(
    			"artless",     "bawdy",	     "beslubbering", "bootless",     "churlish",
    			"cockered",    "clouted",    "craven",       "currish",	     "dankish",
    			"dissembling", "droning",    "errant",       "fawning",	     "fobbing",
    			"froward",     "frothy",     "gleeking",     "goatish",	     "gorbellied",
    			"impertinent", "infectious", "jarring",	     "loggerheaded", "lumpish",
    			"mammering",   "mangled",    "mewling",	     "paunchy",	     "pribbling",
    			"puking",      "puny",       "qualling",     "rank",         "reeky",
    			"roguish",     "ruttish",    "saucy",	     "spleeny",      "spongy",
    			"surly",       "tottering",  "unmuzzled",    "vain",         "venomed",
    			"villainous",  "warped",     "wayward",	     "weedy",        "yeasty" );
     
    	private static List insults = Arrays.asList(
    			"base-court",     "bat-fowling",    "beef-witted",    "beetle-headed",  "boil-brained",
    			"clapper-clawed", "clay-brained",   "common-kissing", "crook-pated",    "dismal-dreaming",
    			"dizzy-eyed",     "doghearted",	    "dread-bolted",   "earth-vexing",   "elf-skinned",
    			"fat-kidneyed",   "fen-sucked",	    "flap-mouthed",   "fly-bitten",     "folly-fallen",
    			"fool-born",      "full-gorged",    "guts-griping",   "half-faced",     "hasty-witted",
    			"hedge-born",     "hell-hated",	    "idle-headed",    "ill-breeding",   "ill-nurtured",
    			"knotty-pated",   "milk-livered",   "motley-minded",  "onion-eyed",     "plume-plucked",
    			"pottle-deep",    "pox-marked",     "reeling-ripe",   "rough-hewn",     "rude-growing",
    			"rump-fed",       "shard-borne",    "sheep-biting",   "spur-galled",    "swag-bellied",
    			"tardy-gaited",   "tickle-brained", "toad-spotted",   "unchin-snouted", "weather-bitten" );
     
    	private static List nouns = Arrays.asList(
    			"apple-john",    "baggage",     "barnacle",       "bladder",     "boar-pig",
    			"bugbear",       "bum-bailey",  "canker-blossom", "clack-dish",  "clotpole",
    			"coxcomb",       "codpiece",    "death-token",    "dewberry",    "flap-dragon",
    			"flax-wench",    "flirt-gill",  "foot-licker",    "fustilarian", "giglet",
    			"gudgeon",       "haggard",     "harpy",          "hedge-pig",   "horn-beast",
    			"hugger-mugger", "joithead",    "lewdster",       "lout",        "maggot-pie",
    			"malt-worm",     "mammet",      "measle",         "minnow",      "miscreant",
    			"moldwarp",      "mumble-news", "nut-hook",       "pigeon-egg",  "pignut",
    			"puttock",       "pumpion",     "ratsbane",       "scut",        "skainsmate",
    			"strumpet",      "varlot",      "vassal",         "whey-face",   "wagtail" );
     
    	/**
    	 * Generate an integer random number between the low and high values
    	 * @param low the minimum random number boundary
    	 * @param high the maximum random number boundary
    	 * @return a random number between <b>low</b> and <b>high</b> 
    	 */
    	public static int randomNumber(int low, int high) {
    		return wheel.nextInt(high - low + 1) + low;
    	}
     
    	/**
    	 * Generate an insult using random numbers to access elements of the insult array lists
    	 * @return an insult
    	 */
    	public static String randomInsult() {
    		int indexAdjective = randomNumber(0, adjectives.size() - 1);
    		int indexInsult = randomNumber(0, insults.size() - 1);
    		int indexNoun = randomNumber(0, nouns.size() - 1);
     
    		StringBuffer generatedInsult = new StringBuffer(50);
    		generatedInsult.append(adjectives.get(indexAdjective));
    		generatedInsult.append(" ");
    		generatedInsult.append(insults.get(indexInsult));
    		generatedInsult.append(" ");
    		generatedInsult.append(nouns.get(indexNoun));
     
    		return generatedInsult.toString();
    	}
     
    	/**
    	 * Generate an insult using the Collections shuffle method to randomise the order of the elements
    	 * within each array list
    	 * @return an insult
    	 */
    	public static String shuffleInsult() {
    		// Rather than get a random element simply shuffle the lists.
    		// Then grab the first values from each list which will be random
    		Collections.shuffle(adjectives);
    		Collections.shuffle(insults);
    		Collections.shuffle(nouns);
     
    		StringBuffer generatedInsult = new StringBuffer(50);
    		generatedInsult.append(adjectives.get(0));
    		generatedInsult.append(" ");
    		generatedInsult.append(insults.get(0));
    		generatedInsult.append(" ");
    		generatedInsult.append(nouns.get(0));
     
    		return generatedInsult.toString();
    	}
     
    	/**
    	 * Included so that a single object could provide a self contained runnable example,
    	 * i.e. no client object required.
    	 * @param args any passed values are ignored
    	 */
    	public static void main(String[] args) {
    		for (int i = 0; i < 5; i++) {
    			System.out.println(i + ": Shuffle => " + shuffleInsult());
    		}
     
    		for (int i = 0; i < 5; i++) {
    			System.out.println(i + ": Random => " + randomInsult());
    		}
    		System.exit(0);
    	}
    }

    The client:

    package org.r3dux.clients;
     
    import org.r3dux.misc.GenerateInsult;
     
    public class ClientInsult {
    	/**
    	 * Shows how the GenerateInsult object can be used in client code
    	 * @param args any passed values are ignored
    	 */
    	public static void main(String[] args) {
    		for (int i = 0; i < 5; i++) {
    			System.out.println(i + ": Shuffle => " + shuffleInsult());
    		}
     
    		for (int i = 0; i < 5; i++) {
    			System.out.println(i + ": Random => " + randomInsult());
    		}
    		System.exit(0);
    	}
    }
    1. Most impressive, sir!

      However I’ll see your beautiful Java code and lower you some shonky JavaScript!

      Brace thyself…


      You have to mung it together with no white-space for it to work properly in WordPress, otherwise it adds stuff like <p> tags on any blank lines, and that breaks it big time. However, that in itself is a useful thing to know – I only managed to figure out why it wasn’t working by going through the code with FireBug and seeing those pesky tags – and that’s when the code was entered in HTML mode not with the WYSIWYG editor, too! Very sketchy…

      Anyways, the javascript for this is:

      var adjective       = "";
      var insult          = "";
      var noun            = "";
       
      var adjectives = [ "artless",     "bawdy",     "beslubbering", "bootless",     "churlish",
      		   "cockered",    "clouted",    "craven",      "currish",      "dankish",
      		   "dissembling", "droning",    "errant",      "fawning",      "fobbing",
      		   "froward",     "frothy",     "gleeking",    "goatish",      "gorbellied",
      		   "impertinent", "infectious", "jarring",     "loggerheaded", "lumpish",
      		   "mammering",   "mangled",    "mewling",     "paunchy",      "pribbling",
      		   "puking",      "puny",       "qualling",    "rank",         "reeky",
      		   "roguish",     "ruttish",    "saucy",       "spleeny",      "spongy",
      		   "surly",       "tottering",  "unmuzzled",   "vain",         "venomed",
      		   "villainous",  "warped",     "wayward",     "weedy",        "yeasty" ];
       
      var insults = [    "base-court",     "bat-fowling",    "beef-witted",    "beetle-headed",  "boil-brained",
      	           "clapper-clawed", "clay-brained",   "common-kissing", "crook-pated",    "dismal-dreaming",
      	           "dizzy-eyed",     "doghearted",     "dread-bolted",   "earth-vexing",   "elf-skinned",
      	           "fat-kidneyed",   "fen-sucked",     "flap-mouthed",   "fly-bitten",     "folly-fallen",
      	           "fool-born",      "full-gorged",    "guts-griping",   "half-faced",     "hasty-witted",
      	           "hedge-born",     "hell-hated",     "idle-headed",    "ill-breeding",   "ill-nurtured",
      	           "knotty-pated",   "milk-livered",   "motley-minded",  "onion-eyed",     "plume-plucked",
      	           "pottle-deep",    "pox-marked",     "reeling-ripe",   "rough-hewn",     "rude-growing",
      	           "rump-fed",       "shard-borne",    "sheep-biting",   "spur-galled",    "swag-bellied",
      	           "tardy-gaited",   "tickle-brained", "toad-spotted",   "unchin-snouted", "weather-bitten" ];
       
      var nouns = [      "apple-john",    "baggage",     "barnacle",       "bladder",     "boar-pig",
                         "bugbear",       "bum-bailey",  "canker-blossom", "clack-dish",  "clotpole",
                         "coxcomb",       "codpiece",    "death-token",    "dewberry",    "flap-dragon",
                         "flax-wench",    "flirt-gill",  "foot-licker",    "fustilarian", "giglet",
                         "gudgeon",       "haggard",     "harpy",          "hedge-pig",   "horn-beast",
                         "hugger-mugger", "joithead",    "lewdster",       "lout",        "maggot-pie",
                         "malt-worm",     "mammet",      "measle",         "minnow",      "miscreant",
                         "moldwarp",      "mumble-news", "nut-hook",       "pigeon-egg",  "pignut",
                         "puttock",       "pumpion",     "ratsbane",       "scut",        "skainsmate",
                         "strumpet",      "varlot",      "vassal",         "whey-face",   "wagtail" ];
       
       
      function randRange(min, max)
      {
             return Math.floor(Math.random() * (max - min + 1) + min);
      }
       
      function getRandomElement(theArray)
      {
      	return theArray[randRange(0, theArray.length - 1)];
      }
       
      function getNewInsult()
      {
      	// Get a random element from each of the arrays...
      	adjective = getRandomElement(adjectives);
      	insult    = getRandomElement(insults);
      	noun      = getRandomElement(nouns);
       
      	// ...then combine and replace the content with our new insult!
      	document.getElementById('generatedInsult').innerHTML = "Thou " + adjective + " " + insult + " " + noun + "!";
      }

      Which if you put together into a standalone page, you end up with something like this (opens in new tab).

      1. Impressive, I like that

        ** Clicks on imaginary ‘I Like This’ button **

        Uses generate button instead
        => Thou warped fen-sucked clack-dish!

        1. The “Like” button on this page is not imaginary, you just don’t have a Bookface account!

          [clicks on imaginary “Like That Shet Likes This” button] =P

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.