#!/usr/local/bin/perl

# $element_count = scalar(@whatever);

@nouns_lite = ('bunnies','dog','cheese','edifice','light',
  'philosophy','machine gun','hamburger','scent','panties',
  'kitty','thoughts','hair piece','ego','puppies','bowling shoes',
  'cheerleader','thing','Barney','grass','trees','paper','ballot',
  'flower','organ','Canada','year','board','wheels','calm',
  'truth','respect','goldfish','velcro','flat tax','angel');

@nouns_dark = ('devil','blade','bunnies','shadow','shadows','pool',
  'oppression','door knob','greed','cue ball','mole','corpse',
  'tragedy','thoughts','envelope','office','cigar','gravity',
  'tombstone','Godzilla','weeds','cavern','organ','storm','hatred',
  'fear','keyboard','Cambodia','defeat','poverty','dismay',
  'ice','maggot','dogs','rage','blight','captain','leather');

@verbs_dark = ('slice','pine','loathe','cut','mourn','run',
  'travel','walk','cry','juggle','burn','wail','kill','die',
  'reject','hate','roll','lie','excuse','spurn','deny','swim',
  'suffocate','drag','possess','watch','fear','whirl','ignore',
  'regret','take','slap','vandalize','tremble','brood');

@verbs_lite = ('kiss','run','walk','laugh','smile','hold','hug',
  'verify','idolize','rock','eat','live','heal','gamble','grasp',
  'roll','love','bounce','excuse','create','give','accept','swim',
  'protect','giggle','spy','congratulate','open','sit','bathe',
  'perk up','slide','cope','lope','drink','spin');

@verbps_dark = ('thinking','feeling','running','killing','cutting',
  'chanting','pounding','wishing','destroying','walking','waiting',
  'hating','annoying','pretending');

@verbps_lite = ('thinking','feeling','running','walking','healing',
  'wishing','creating','enlightening','hugging','smiling','realizing',
  'considering','bathing','flapping');

@connectors = ('in the','from the','under the','with the','above the',
  'at the','beneath the','on top of the ','within the','without the',
  'from a','without a','in a','beneath a','above a','on a');

@adjectives_dark = ('scary','dark','black','jumbled','red','blue',
  'rhetorical','absurd','defiant','deadly','insane','tragic',
  'comic','wooden','stupid','foolhardy','old','pointless','flappy',
  'moody','humorless','grimy','slimy','dry','artless','nameless',
  'sullen');

@adjectives_lite = ('nice','bright','happy','hoppy','cute','gregarious',
  'sexy','light','bouncy','orange','pink','ridiculous','silly',
  'crazy','fruitful','brilliant','comic','hard','lively','funny',
  'enlightened','goofy','respectful','languid','watery','yellow');


use CGI;
$query = new CGI;
print $query->header;

if($query->param) {

  srand;

  if ($query->param('Form') eq "Three Line Repeat") {
    $form = 1;
  }

  if ($query->param('Form') eq "Five Line") {
    $form = 2;
  }

  if ($query->param('Form') eq 
  "Quadruple Six-Line Redundant Spinal By-Pass") {

    $form = 3;
  }


  $topic = $query->param('Topic');
  $mood = $query->param('Mood');

  if ($form == 1) {
    $poem = &create_three_line;
  }

  if ($form == 2) {
    $poem = &create_five_line;
  }

  if ($form == 3) {
    $poem = &create_six_line;
  }

  print $query->start_html($title);


  print  $poem;

  print "<hr>\n" .
  "Okay, so it ain't exactly Walt Whitman.<p>\n";
  print 
  "<a href=\"http://www.intranet.org/~tdh\">" .
  "Back to Tim's page</a>\n";

  print $query->end_html;
  exit 0;

}

sub create_three_line {

  $repeat_line = &get_pronoun . &get_verb . &get_connector . &get_noun .
  "of " . &get_noun . "\n";


    $stuff = &get_title . 
    $repeat_line . "<br>\n" .
    &get_verb_present . &get_connector . &get_noun . "of " . $topic . 
    "<br>\n" .
    "Oh, " . &get_adjective . $topic . ".\n<p>\n" .
    $repeat_line . "<br>\n" .
    &get_verb_present . &get_connector . &get_noun . "of " . $topic .
    "<br>\n" .
    "Oh, " . &get_adjective . $topic . ".\n<p>\n" .
    $repeat_line . "<br>\n" .
    &get_verb_present . &get_connector . &get_noun . "of " . $topic .
    "<br>\n" .
    "Oh, " . &get_adjective . $topic . ".\n<p>\n" .
    " ";
    
     


  return $stuff;

} 

sub create_five_line {

  $stuff = &get_title .

  &get_verb_present . &get_connector . &get_adjective .
  &get_noun . "<br>\n" .
  &get_verb_present . &get_connector . &get_adjective . &get_noun .
  "<br>\n" .
  &get_verb_present . &get_connector . &get_adjective . &get_noun .
  "<br>\n" .
  &get_verb_present . &get_connector . &get_adjective . &get_noun .
  "<br>\n" .
  &get_pronoun . &get_verb . &get_connector . &get_noun . "of ".
  $topic . ".\n<p>\n";

}

sub create_six_line {

  

  $repeat_verb_adj_noun_seq = &get_verb_present . &get_adjective .
  &get_noun;

  $repeat_paragraph = &get_verb_present . &get_connector .
  &get_adjective . &get_noun . "of " . $topic . "<br>\n" .
  "the " . &get_noun . &get_verb . "for " . &get_noun . "<br>\n" .
  &get_verb_present . &get_connector . &get_noun . "of " . &get_noun .
  "<br>\n" .
  $repeat_verb_adj_noun_seq . "of " . &get_noun . "<br>\n" . 
  &get_pronoun . &get_verb . &get_connector . &get_noun .
  &get_connector . &get_noun . "<br>\n" .
  $repeat_verb_adj_noun_seq . "of " . $topic . "<p>\n";

  $stuff = &get_title .
 
  $repeat_paragraph .

  &get_noun . "of " . &get_noun . "<br>\n" .
  &get_verb_present . &get_adjective . &get_noun . "<br>\n" .
  &get_noun . "<br>\n" .
  &get_noun . &get_s_connector . $topic . "'s " . &get_noun . "<br>\n" .
  $repeat_verb_adj_noun_seq . "with " . &get_noun . "<br>\n" . 
  &get_noun . "<p>\n" .

  $repeat_paragraph .

  &get_noun . "of " . &get_noun . "<br>\n" .
  &get_verb_present . &get_adjective . &get_noun . "<br>\n" .
  &get_noun . "<br>\n" .
  &get_noun . &get_s_connector . $topic . "'s " . &get_noun . "<br>\n" .
  $repeat_verb_adj_noun_seq . "with " . &get_noun . "<br>\n" .
  &get_noun . "<p>\n"; 

  return $stuff;

}


sub get_title {

  $number = int(rand(10));

  if($mood eq "Bitter and Angst-ridden") {

    if($number == 1) {
      $title = "Fishing with $topic";
    }
    if($number == 2) {
      $title = "Still life with $topic";
    }
    if($number == 3) {
      $title = "I ran over $topic in my \'75 Buick";
    }
    if($number == 4) {
      $title = "The tragedy of $topic";
    }
    if($number == 5) {
      $title = "How $topic killed my brother";
    }
    if($number == 6) {
      $title = "$topic and Reaganomics:  Connected at the elbows";
    }
    if($number == 7) {
      $title = "Death, Taxes, and $topic";
    }
    if($number == 8) {
      $title = "A little obsessive, aren't we?";
    }
    if($number == 9) {
      $title = "Living under the shadow of $topic";
    }
    if(!$title) {
      $title = "Death to $topic";
    }

  } else {

    if($number == 1) {
      $title = "I Love $topic";
    }
    if($number == 2) {
      $title = "$topic and You";
    }
    if($number == 3) {
      $title = "The Unbearable Lightness of $topic";
    }
    if($number == 4) {
      $title = "Have you hugged $topic today?";
    }
    if($number == 5) {
      $title = "$topic dances a little jig";
    }
    if($number == 6) {
      $title = "Running hand in hand with $topic";
    }
    if($number == 7) {
      $title = "Portrait of $topic";
    }
    if($number == 8) {
      $title = "Ya know, $topic\'s O.K. by me";
    }
    if($number == 9) {
      $title = "$topic and Family Values";
    }
    if(!$title) {
      $title = "Come Walk with $topic";
    }

  }

  return "<h2>" . $title . "</h2><p>\n";

}

sub get_noun {

  if($mood eq "Bitter and Angst-ridden") {
    @nouns = @nouns_dark;
  } else {
    @nouns = @nouns_lite;
  }

  $number_of_nouns = scalar(@nouns);
  $noun_number = int(rand($number_of_nouns));
  $noun = @nouns[$noun_number] . " ";
  return $noun;

}

sub get_verb {

  if($mood eq "Bitter and Angst-ridden") {
    @verbs = @verbs_dark;
  } else {
    @verbs = @verbs_lite;
  }

  $number_of_verbs = scalar(@verbs);
  $verb_number = int(rand($number_of_verbs));
  $verb = @verbs[$verb_number] . " ";
  return $verb;

}

sub get_verb_present {
 
  if($mood eq "Bitter and Angst-ridden") {
    @verbps = @verbps_dark;
  } else {
    @verbps = @verbps_lite;
  }
 
  $number_of_verbps = scalar(@verbps);
  $verbp_number = int(rand($number_of_verbps));
  $verbp = @verbps[$verbp_number] . " ";
  return $verbp;
 
}

sub get_connector {
 
  $number_of_connectors = scalar(@connectors);
  $connector_number = int(rand($number_of_connectors));
  $connector = @connectors[$connector_number] . " ";
  return $connector;
 
}

sub get_s_connector {

  $s_connector = &get_connector;
  @s_words = split(/ /,$s_connector);
  return $s_words[0] . " ";

}

sub get_adjective {
 
  if($mood eq "Bitter and Angst-ridden") {
    @adjectives = @adjectives_dark;
  } else {
    @adjectives = @adjectives_lite;
  }
 
  $number_of_adjectives = scalar(@adjectives);
  $adjective_number = int(rand($number_of_adjectives));
  $adjective = @adjectives[$adjective_number] . " ";
  return $adjective;
 
}

sub get_pronoun {
 
#  if($mood eq "Bitter and Angst-ridden") {
#    @verbs = @verbs_dark;
#  } else {
#    @verbs = @verbs_lite;
#  }
 
#  $number_of_verbs = scalar(@verbs);
#  $verb_number = int(rand($number_of_verbs));
#  $verb = @verbs[$verb_number] . " ";
#  return $verb;
  return "I ";
 
}


print $query->start_html("Tim's Amazing Poem Generator");
print $query->start_form;

print "<h1> Tim's Amazing Poem Generator </h1>\n";
print "<hr>\n";
print "I've become much too lazy to write poetry lately, so I\n" .
      "thought I'd put together a little perl script that would\n" .
      "write them for me.  After all, a world without my brilliant\n" .
      "poetry would be... er, something.\n";
print "<hr>\n";

print "Poem Form: \n" .
      $query->popup_menu('Form',['Three Line Repeat','Five Line',
      'Quadruple Six-Line Redundant Spinal By-Pass']);

print "<p>\n";

print "Select a Primary Topic: \n" .
      $query->popup_menu('Topic',['Spam',
      'The Military-Industrial Complex', 'Windows 95', 'It',
      'Your Mother', 'Bob Dole', 'Chicken Gravy', 'Elvis',
      'Brain Surgery', 'Voodoo', 'Bill Clinton',
      'Jesus','Bathing Suit','Republican','Sillyness',
      'Penis Envy','Bill Gates','The Sanctimony of Marriage',
      'Bob','Tiny Tim','The Garbage Man']) . "\n";

print "<p>\n";

# print "Enter a Wild-card word:" .
#       $query->textfield('WildWord') . "\n";

# print "<p>\n";

print "What is the general mood of the piece? \n <p>\n" .
      $query->radio_group('Mood',['Bitter and Angst-ridden',
      'Sickeningly Cheerful']);

print "<p>\n";

print $query->submit("Compose a Masterpiece") . $query->reset . "\n";

print "<p>\n";
print $query->end_form;
print
  "<a href=\"http://www.intranet.org/~tdh\">Back to Tim's page</a><p>";

print $query->end_html;


