Converting from integers to output

Peter Maas peter.maas at mplusr.de
Wed Jul 14 03:40:16 EDT 2004


Krista Bailie schrieb:
> and I know I need to create a fraction for each color by using the formula,
> fraction = (i+1.0)/nsteps
> r = (1-fraction)*red1 + fraction*red2
> 
> but the program won't recognize i... anyway, here is the html...if anyone
> can give me any help I'd be so grateful!!

def longtorgb(c):
     '''long to (r,g,b) tuple assuming that r
     the r bits are high and the b bits are low'''

     return ((c & 0xff0000) >> 16, (c & 0xff00) >> 8, c & 0xff)

colorstring = ""
for i in range(nsteps+1):
     fraction = i/nsteps
     mix = (1-fraction)*red1 + fraction*red2
     rgb = longtorgb(mix)
     colorstring += "color %d is rgb(%d,%d,%d)\n" % ((i,)+rgb)

This is a start. You can insert tuples in a html string with the
formatting operator (%). Literal % characters in the string have to
be doubled if you are using the formatting operator.

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