[Tutor] How do you make yellow?
Magnus Lycka
magnus@thinkware.se
Fri Nov 22 19:36:08 2002
At 17:40 2002-11-22 -0500, James M Lang wrote:
>While trying to figure out how to change colors from the example on the=20
>livewires package, I was wondering how a TV would create yellow,=20
>considering that it only has red, green, and blue. It's been mystifying =
me.
To make this a bit python related: The following program will
generate tables with 216 (6*6*6) colours. A text in a cell
like "R40% G00% B40%" means Red: 40%, Green 0% and Blue 40%.
The program will create a file called colorcube.html. Inspect
it with a web browser such as Mozilla or MS IE.
# colorcobe.py, Magnus Lyck=E5, 2002
page =3D """<html><head><title>Color Cube</title></head>
<body>
%s
</body></html>"""
table =3D "<table>%s</table>"
row =3D "<tr>%s</tr>"
cell =3D """<td bgcolor=3D"#%(red)02X%(green)02X%(blue)02X">
<font color=3D"white">R%(redP)02i%% G%(greenP)02i%%
B%(blueP)02i%%</font><br>
<font color=3D"black">R%(redP)02i%% G%(greenP)02i%%
B%(blueP)02i%%</font>"""
safeColors =3D range(0, 256, 51)
tables =3D []
for red in safeColors:
redP =3D red / 2.55
rows =3D []
for green in safeColors:
greenP =3D green / 2.55
cells =3D []
for blue in safeColors:
blueP =3D blue / 2.55
cells.append(cell % locals())
rows.append(row % "\n".join(cells))
tables.append(table % "\n".join(rows))
o =3D file('colorcube.html', 'wt')
print >> o, page % "\n".join(tables)
o.close()
--=20
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se