[Tutor] Help with % conversion to output colour
Cassandra Peachey
cpeachey at sfu.ca
Sat Jul 18 04:53:44 CEST 2009
Hi,
I'm working on an assignment that requires the user RGB requested output to create a colour block in fractional steps. I'm pretty much down to the last bit, however, I've hit a road block in that my percentages are not showing as a colour block but as the <div> tag percentages.
Any suggestions on what I'm missing to output the %'s into the colour block showing colour?
Thanks for any help.
Cassandra
import cgi
form = cgi.FieldStorage()
# print HTTP/HTML header stuff
print "Content-type: text/html"
print
print"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd ";>
<html xmlns=" http://www.w3.org/1999/xhtml "; xml:lang="en" lang="en">
<head>
<title>Colour Blend</title>
<style type="text/css">
#blend {
width: 10em;
padding: 0;
border: 1px solid black;
margin-left: 3em;
}
.colourblock {
width: 10em;
height: 1em;
}
</style>
</head>
<body>
<h1>Colour Blend</h1>
<p>Here is a mix of the colours you specified:</p>
<div id="blend">"""
red1 = int(form["red1"].value)
green1 = int(form["green1"].value)
blue1 = int(form["blue1"].value)
red2 = int(form["red2"].value)
green2 = int(form["green2"].value)
blue2 = int(form["blue2"].value)
nsteps = int(form["steps"].value)
if nsteps > 150:
nsteps = 150
for i in range(0,nsteps-1):
fraction = (i+1.0)/nsteps
r = (1-fraction)*red1 + fraction*red2
g = (1-fraction)*green1 + fraction*green2
b = (1-fraction)*blue1 + fraction*blue2
print '<div class="colourblock" style="background-color: rgb(' + str(r) + '%,' + str(g) + '%,' + str(b) + '%'"> </div>"
print "</body></html>"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090717/80f50472/attachment.htm>
More information about the Tutor
mailing list