index.cgi
changeset 11 0f070e9daa71
parent 10 6add80d3993b
child 12 aa6b83c94528
--- a/index.cgi	Tue May 05 18:10:25 2009 +0300
+++ b/index.cgi	Tue May 05 18:14:44 2009 +0300
@@ -95,7 +95,19 @@
 
     return l
 
-def build_data (text, chars, line_colors, random_chars, random_text) :
+def randomize_str_char (str) :
+    """
+        Randomize the given string by moving one char around
+    """
+
+    l = list(str)
+
+    c = l.pop(random.randint(0, len(l) - 1))
+    l.insert(random.randint(0, len(l)), c)
+
+    return ''.join(l)
+
+def build_data (text, chars, line_colors, random_chars=True, random_text=False, random_text_char=False) :
     """
         Returns a matrix of (text, color) tuples representing the data to render
 
@@ -104,8 +116,9 @@
             text        - list of lines
             chars       - list of random chars to interpse
             line_colors - list of colors to draw the chars in
-            random_chars - randomize the lines the chars go in
-            random_text - randomize the chars in each line
+            random_chars        - randomize the lines the chars go in
+            random_text         - randomize the chars in each line
+            random_text_char    - randomize each line by moving one char around
     """
 
     data = []
@@ -122,6 +135,9 @@
 
         if random_text :
             line = ''.join(randomize(line))
+
+        if random_text_char :
+            line = randomize_str_char(line)
         
         # split into three parts
         if char :
@@ -271,6 +287,7 @@
     Option('lang',          False,  str,        Defaults.text_lang,     TEXT_BY_LANG.keys()),
     Option('text',          True,   unicode,    None,                   None),
     Option('random-text',   False,  arg_bool,   False,                  None),
+    Option('random-text-char', False, arg_bool, False,                  None),
     Option('chars',         True,   unicode,    Defaults.chars,         None),
     Option('random-chars',  False,  arg_bool,   True,                   None),
     Option('colors',        True,   arg_color,  Defaults.colors,        None),
@@ -311,7 +328,7 @@
         raise ValueError(opts['font-size'])
     
     # load/prep resources
-    data = build_data(opts['text'], opts['chars'], opts['colors'], opts['random-chars'], opts['random-text'])
+    data = build_data(opts['text'], opts['chars'], opts['colors'], opts['random-chars'], opts['random-text'], opts['random-text-char'])
     font = load_font(opts['font'], opts['font-size'])
     
     # render the image