Converting from integers to output
Peter Maas
peter.maas at mplusr.de
Thu Jul 15 04:21:36 EDT 2004
Krista Bailie schrieb:
> Okay, I've almost got this, but I still don't understand how to actually
> make the data appear.
import cgi
def longtorgb(c):
'''long to (r,g,b) tuple assuming that the
r bits are high and the b bits are low'''
return ((c & 0xff0000) >> 16, (c & 0xff00) >> 8, c & 0xff)
if __name__ == '__main__':
form = cgi.FieldStorage()
# fetch input
#col1 = int(form['color1'].value)
#col2 = int(form['color2'].value)
# test only , to be deleted
col1 = 0xff # blue
col2 = 0xff00 # green
nsteps = 5
print col1, col2
# print header
print 'Content-type: text/html\n'
# print static part 1
print '''
<html>
<head>
<title>
Blending colors
</title>
</head>
<body>
Here is a mix of the two colours you specified:
'''
# print blend fields
for i in range(nsteps+1):
fraction = float(i)/nsteps
mix = int((1.0-fraction)*col1 + fraction*col2)
rgb = longtorgb(mix)
print '''
<div style="width: 50px; height: 20px; background: rgb(%d,%d,%d)">
step %d
</div>
''' % (rgb+(i,))
# print static part 2
print '''
</body>
</html>
'''
Mit freundlichen Gruessen,
Peter Maas
--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------
More information about the Python-list
mailing list