The prof gave us these formulas:
fraction = (i+1.0)/nsteps
r = (1-fraction)*red1 + fraction*red2
To make one of those bars:
<div class="colourblock" style="background-color: rgb(100.0%,50.0%,0.0%)"> </div>
print 'style="background-color: rgb(' + str® + '%'
Here is the whole code I got so far
import cgi
form = cgi.FieldStorage()
red1 = int(form ["red1"].value)
red2 = int(form ["red2"].value)
blue1 = int(form ["blue1"].value)
blue2 = int(form ["blue2"].value)
green1 = int(form ["green1"].value)
green2 = int(form ["green2"].value)
nsteps = int(form["nsteps"].value)
def fraction():
fraction = i+1.0/nsteps
def colourblock(red1, red2, blue1, blue2, green1, green2):
b = (1-fraction)*blue1 + fraction*blue2
r = (1-fraction)*red1 + fraction*red2
g = (1-fraction)*green1 + fraction*green2
print"""Content-type: text/html
<!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">
<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>
"""
print"""
<h1>Colour Blend</h1>
<p>Here is a mix of the two colours you specified:</p>
<div id="blend">
for i in range(nsteps):
print i,
<div class="colourblock" style="background-color: rgb(r%,b%,g%)"> </div>
</div>
<hr class="footsep">
<p class="footlink">Return to <a href="http://cmpt165.cs.sfu.ca/~mja26/">the index</a>.</p>
</body>
"""
I know that the data have to be looped somehow but I have no idea where to start. Any help would be greatly appreciated.
This post has been edited by dumbstruckk: 16 July 2009 - 12:03 AM

New Topic/Question
Reply



MultiQuote


|