|< Day Day Up >|
Hack 63 Create Comic Strips
IRC chat certainly has its moments. Wouldn't it be great if you could immortalize some of these moments in the form of a comic strip?
At times, an ordinary conversation on IRC turns into something much more amusing. People take funny quotes (quite often out of context) and plaster them all over the Web so other people can enjoy the humor. One of the most popular IRC quotes web sites is http://www.bash.org, which contains thousands of manually approved funny quotes.
Plain text quotes are all very well, but there's no reason they can't be made into comic strips. ComicBot (http://www.jibble.org/comicbot) is an IRC bot based on the PircBot framework that sits quietly in a channel and observes what people say. If somebody utters "lol" or suchlike, the bot assumes that something funny has been said and uses the last few lines to fill in a comic strip template.
9.7.1 Setting Up ComicBot
ComicBot can be downloaded from http://www.jibble.org/comicbot. The ZIP file contains the source code, the compiled bytecode, and several comic strip templates.
The first step is to edit the configuration file, so open bot.ini in your favorite text editor. You'll find several settings in this file that you will need to change:
nick = MyComicBot login = comicbot server = irc.freenode.net channel = #channel outputDirectory = /home/paul/webpages/comicbot helpString = Check out the latest cartoon at http://www.jibble.org/comicbot/
You can change the nickname of your ComicBot by changing the nick setting. You will need to make sure you set it to something that isn't already in use on the server. The server and channel let you tell the bot what to connect to and which channel to join. When the bot creates a new comic strip, it will write it to the outputDirectory, so make sure this directory is writable by the bot. Finally, the helpString is what the bot says when people ask the bot for help. It is always a good idea to provide a help feature in a bot so that other users can establish what its purpose is, for example:
<Paul> ComicBot: help <ComicBot> Check out the latest cartoon at http://www.jibble.org/comicbot/
9.7.2 Running ComicBot
Windows users can simply double-click on run.bat to launch ComicBot (the program is already compiled, so you will only need to run comp.bat to compile the source code if you have made any changes to it).
% java -classpath .:./pircbot.jar CartoonStripBot
After the bot has been started, you should see it connect to the IRC server and join the channel specified in bot.ini. Leave the bot running for a while and you will see each comic strip generated and stored in the output directory.
9.7.3 Comic Strip Templates
Each time ComicBot sees something that it believes is funny, it will randomly pick one of the templates stored in the data directory and use it to create a comic strip. Each template consists of two files—a configuration file and a background image. For example, the first template in this directory would consist of the files strip1.ini and strip1.png.
Making your own template is straightforward. The easiest method is to copy an existing template, alter the PNG image, and edit the configuration file in a text editor. The configuration file will start by setting the filename of the background image:
background = strip1.png
This particular background image looks like Figure 9-7.
Figure 9-7. A simple background image for a template
ComicBot will write a date stamp on the output so that you know when each comic strip was generated. The datestamp setting is used to specify the x,y coordinate of where this should be placed, so make sure you know how big your background image is and that there is a suitable area of whitespace for the date stamp to be written. Figure 9-7 provides room for a date stamp along the bottom left.
datestamp = 11,261
Each template background should contain white regions that can be used to write each part of the IRC quote. The inner bounding box of the first "speech bubble" is defined like so:
bubble1 = 29,65,146,82 maxlength1 = 100
This means that the first line of text to be placed in the comic strip will be fitted into a rectangle with a top-left coordinate of (29,65), with a width of 146 and height of 82. The ComicBot will shrink the text if necessary so it fits nicely. However, if there is too much text, it could become so small it is unreadable. In this case, the maximum length of the speech bubble has been limited to 100 characters. If there are more than 100 characters, ComicBot will simply give up instead of producing a comic strip with small, unreadable text. The next speech bubble coordinates are specified with bubble2 and so on.
Once you have made the template, you should end up with something like Figure 9-8.
Figure 9-8. A complete comic strip created from the template
|< Day Day Up >|