Personal tools

User:Maze/coolscale.py

From Eth0Wiki

< User:Maze
Revision as of 13:29, 29 January 2010 by Maze (talk | contribs) (New page: = Code= <pre> #! /usr/bin/env python # dirty coolscale generator, yes this could be written in far less lines, # care-- and lazy++ :) # # - maze import sys if len(sys.argv) != 2 or not ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Code

#! /usr/bin/env python
# dirty coolscale generator, yes this could be written in far less lines,
# care-- and lazy++ :)
#
# - maze

import sys

if len(sys.argv) != 2 or not sys.argv[1].isdigit():
    print >>sys.stderr, '%s <rows>' % (sys.argv[0],)

rows = int(sys.argv[1])
bit  = float(0xff) / float(rows)

print '{|'
for x in xrange(0, rows):
    if x > 0:
        c = 0xff - (bit * x)
    else:
        c = 0xff
    if x == 0:
        d = 0x00
    elif x < (rows - 1):
        d = 0x00 + (bit * x)
    else:
        d = 0xff
    if x:
        print '|-'
    print '|style="background:#%02X00%02X;color:#FFF"|..' % (c, d)
print '|}'

Example

maze@yourbox ~# python coolscale.py 42
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..