Due: Friday Jan 26, 2006; 10:00PM
Textify
Write a Python script (program) that will take a string as a command-line argument and decorate the individual letters in the string with a random color and font. Your program should print the output to standard out in HTML format.
Here is a sample of how your script should run (the bold lines are what the user types):
$ ./textify.py 'Hello world!' <html> <head><title></title></head> <body><big> <font face="Big Caslon" color="#7961BE">H</font> <font face="Baskerville" color="#62F68C">e</font> <font face="Gill Sans" color="#84C2F3">l</font> <font face="Verdana" color="#AE5B02">l</font> <font face="Big Caslon" color="#3C77F2">o</font> <font face="Optima" color="#FAE093"> </font> <font face="Arial" color="#6C328F">w</font> <font face="Optima" color="#AD449D">o</font> <font face="Big Caslon" color="#AAB45B">r</font> <font face="Lucida Grande" color="#620A33">l</font> <font face="Copperplate" color="#786372">d</font> <font face="Verdana" color="#80B16C">!</font> </big></body> </html> $ ./textify.py textify.py, 2006 Nadeem Abdul Hamid Usage: textify.py [-t page_title] string $ ./textify.py -t 'Test' A <html> <head><title>Test</title></head> <body><big> <font face="Verdana" color="#61B746">A</font> </big></body> </html>
Notes
-
As demonstrated in the examples above, your program should support a command-line option to set the title of the page. If an incorrect set of command-line arguments are supplied, an appropriate usage message should be displayed.
-
You may specify a list of fonts from which to choose in your Python script, such as the following (you are free to use whatever fonts you feel like):
FONTS = ["Optima", "Arial", "Helvetica", "Courier", "Gill Sans", "Baskerville", "Futura", "American Typewriter", "Verdana", "Lucida Grande", "Times", "Big Caslon", "Copperplate"];
-
The Python random library provides functions for generating random numbers and may be useful (link). Assuming
gen
is aRandom
object, here is a code snippet to generate a random integer in [a, b)int( math.floor( gen.uniform(a, b) ) );
-
To generate color tags for each letter, build a string of 6 randomly generated hexadecimal digits (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F), prefixed by the character '#'. For more information on HTML color codes, see here.
-
As a point of comparison, my solution to this problem is 100 lines, including blank lines, comments, doc strings, etc.
Submit
Submit your Python script in the prog01 submit folder for this class.