Let's generate some random no-name Garfield comics.
To begin, we need an unsettlingly-derivative name for the cat, and a suitable subtitle. We're really leaning in to the ‘discount,’ ‘dollar-store,’ “we have Garfield at home” aspect of these titles.
Let's use the proper Garfield fonts, “Alfredo Heavy Regular” for the title and “Garfield Regular” for the tagline:
Then of course we resize to the receipt printer width and crunch it down with 1-bit dithering:
The name-generation algorithm is rather carefully thought-out... we want maximum weirdness while maintaining similarity to the original name (hence the score variable). Cadence and syllables all factor in to the word components.
Notice the weighted-random tagging appended to each string value, which specifies the relative likelihood that any given item will be chosen.
function GarfTaglineGenerate() : string
{
$tag = '';
$tag .= WeightedStringRand (array ('lazy|2', 'fat|2', 'hungry|2', 'grumpy|2', 'pampered|1', 'sarcastic|1', 'overweight|1', 'comical|1', 'furry|1', 'funny|1', 'amusing|1', 'clever|1')) . ' ';
$tag .= WeightedStringRand (array ('cat|6', 'feline|5', 'pet|4', 'animal|4', 'cartoon|3', 'creature|2', 'character|1'));
return ($tag);
}
function GarfNameGenerate() : string
{
do
{
$name = '';
$score = 0;
// --- G ----
$name .= ($part = WeightedStringRand (array ('G|10', 'X|0', 'D|2', 'F|2', 'B|2', 'R|1', 'J|2')));
if ($part == 'G')
$score += 2;
// --- . ----
$part = WeightedStringRand (array ('|10', 'r|2', 'w|1', 'l|2'));
if ($part == '' || mb_endswithi ($name, $part) || in_array ($name . $part, array ('Xw', 'Rw', 'Jw', 'Fw', 'Bw', 'Xr', 'Jr', 'Rl', 'Xl', 'Dl', 'Jl')))
$score++;
else
$name .= $part;
// --- a ----
$name .= ($part = WeightedStringRand (array ('a|5', 'e|2', 'i|1', 'o|2', 'u|1')));
if ($part == 'a')
$score++;
// --- r ----
$name .= ($part = WeightedStringRand (array ('r|5', 'n|2', 'l|2', 's|2', 'd|2', 't|2', 'b|2', 'k|2', 'm|2', 'g|1', 'f|1', 'z|1', 'x|1', 'p|1', '|1')));
if ($part == 'r')
$score++;
// --- f ----
do {
$part = WeightedStringRand (array ('f|10', 'd|2', 'g|2', 's|2', 'n|2', 't|2', 'b|2', 'k|2', 'm|2', 'g|1', 'z|1', 'x|0', 'p|1', 'ph|1', 'sh|1'));
} while (($part != 'f' && mb_endswithi ($name, mb_firstchar ($part)))
|| in_array (mb_lastchar ($name) . $part, array ('zs', 'zsh', 'sz', 'xz', 'xs', 'xsh')));
$name .= $part;
if ($part == 'f')
$score += 3;
// --- ie ----
$name .= ($part = WeightedStringRand (array ('ie|5', 'ee|3', 'oo|2', 'ae|0', 'ou|1', 'a|2', 'e|3', 'i|3', 'o|2', 'u|2')));
if ($part == 'ie')
$score += 2;
else if (in_array ($part, array ('ee', 'e', 'i')))
$score++;
// --- ld ----
$name .= ($part = WeightedStringRand (array ('ld|5', 'd|3', 'g|3', 'lk|2', 'ng|2', 'nk|2', 'k|2', 'rk|2', 'rd|2', 'rf|2', 'lt|2', 't|2', 'nd|2', 'nt|2',
'rds|1', 'pt|1', 'md|0', 'r|1', 's|1', 'ss|1', 'ck|1', 'll|1')));
if ($part == 'ld')
$score += 3;
else if (mb_lastchar ($part) == 'd')
$score += 2;
} while ($score < 7 || mb_containsanyi ($name, array (
'garfield', 'iemd', 'rir', 'rur', 'ooll', 'eell', 'eeld', 'oold',
'god', 'denied', 'golfing', 'golfer', 'refund', 'getfound', 'gunfiend', 'food', 'feed', 'girl', 'barf',
'damn', 'piss', 'fuck', 'shit', 'dick', 'cunt', 'kunt', 'fag', 'porn', 'suck', 'jiz', 'homo', 'poop', 'cock', 'rape', 'kill', 'drug', 'ass', 'gook'))
|| mb_startsanyi ($name, array ('fat', 'fap', 'gag', 'dad', 'jap', 'bad'))
|| mb_endsanyi ($name, array ('fat', 'find')));
return ($name);
}
As a final step we also must filter out inappropriate words and substrings from the random results. Some filters just clear out awkward sequences of consonants and vowels, while others filter out hateful terms and inappropriate sexual references. It's a bit weird to have to put these phrases into code, but it's necessary to produce sanitized results.
The support functions should be obvious, but the full source code, plus fonts are available for download for reference.
Observe some potential results from the random title generator:
Gazfink, the grumpy animal Gemfield, the lazy feline Berfuld, the overweight animal Gerzold, the grumpy pet Glunfeld, the lazy cat Forfild, the clever creature Gapfeek, the hungry animal Donfield, the lazy cartoon Gufieg, the comical pet Gamberd, the clever feline Rarfing, the fat pet Gazfeeg, the fat cat Gamfarf, the pampered creature Garfierf, the fat cartoon Gapfipt, the clever cat Jorfurd, the amusing cat Gamdeed, the clever animal Gokfilk, the grumpy cartoon Gerfouss, the amusing cat Gizfeld, the lazy creature Gofieg, the pampered pet Jarkild, the grumpy cat Glatfeeg, the overweight animal Gerfeeng, the furry pet Faffiet, the fat feline Gafet, the grumpy pet Gonfierds, the comical character Ganshild, the fat cat Grarfied, the grumpy creature Danfod, the fat feline
All-in-all, there are approximately 45,000 possible names, plus 84 unique subtitles. Seems like a good start for a random Garfield generator.