# Converting from integers to output

Krista Bailie bailies at telus.net
Wed Jul 14 19:23:45 CEST 2004

```Okay, I've almost got this, but I still don't understand how to actually
make the data appear.  It is supposed to show up in bars(nsteps) that blend
one color to the other, but I can only get the static html colors to show.
Should I just erase the html div class info and put in a formula instead?
(File is below...)

Many, many thanks,
Krista

import cgi
form = cgi.FieldStorage()
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)

def nsteps():
nsteps = int(raw_input("steps> "))
def red1():
red1 = int(raw_input("red1> "))
def red2():
red2 = int(raw_input("red2> "))
def blue1():
blue1 = int(raw_input("blue1> "))
def blue2():
blue2 = int(raw_input("blue2> "))
def green1():
green1 = int(raw_input("green1> "))
def green2():
green2 = int(raw_input("green2> "))

colorstring = ""
def fraction():
fraction = i/nsteps
def mix():
mix = (1-fraction)*blue1 + fraction*blue2
mix = (1-fraction)*red1 + fraction*red2
mix = (1-fraction)*green1 + fraction*green2
def rgb():
rgb = longtorgb(mix)
colorstring += "color %d is rgb(%d,%d,%d)\n" % ((i,)+rgb)

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">
<title>Colour Blend</title>
<style type="text/css">
#blend {
width: 10em;
border: 1px solid black;
margin-left: 3em;
}
.colourblock {
width: 10em;
height: 1em;
}
</style>
<body>
<h1>Colour Blend</h1>

<p>
Here is a mix of the two colours you specified:
</p>
<div id="blend">

<div class="colourblock" style="background-color: rgb(100.0%,10.0%,10.0%)">
</div>
<div class="colourblock" style="background-color: rgb(100.0%,20.0%,20.0%)">
</div>
<div class="colourblock" style="background-color: rgb(100.0%,30.0%,30.0%)">
</div>
<div class="colourblock" style="background-color: rgb(100.0%,40.0%,40.0%)">
</div>
<div class="colourblock" style="background-color: rgb(100.0%,50.0%,50.0%)">
</div>
<div class="colourblock" style="background-color: rgb(100.0%,60.0%,60.0%)">
</div>
<div class="colourblock" style="background-color: rgb(100.0%,70.0%,70.0%)">
</div>
<div class="colourblock" style="background-color: rgb(100.0%,80.0%,80.0%)">
</div>
<div class="colourblock" style="background-color: rgb(100.0%,90.0%,90.0%)">
</div>
<div class="colourblock" style="background-color:
rgb(100.0%,100.0%,100.0%)"> </div>
</div>

</div>

</body>
</html>"""

"Krista Bailie" <bailies at telus.net> wrote in message
news:FV3Jc.43514\$Rf.4604 at edtnps84...
> I'm sure this is so easy that it will hurt for anyone to read it, but I
> really need some direction.  I'm trying to create a color chart (RGB) that
> shows steps between two different colors as entered by the user.  I know
the
> web script must convert the values into integers, store them as variables
> and then output them, but I cannot seem to establish the calculation for
> this.  I'm attaching the html I've got, that works when the page is
static,
> 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!!
>
> Thanks,
> Krista
>
> import cgi
> form = cgi.FieldStorage()
> 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">
> <title>Colour Blend</title>
> <style type="text/css">
> #blend {
>   width: 10em;
>   border: 1px solid black;
>   margin-left: 3em;
> }
> .colourblock {
>   width: 10em;
>   height: 1em;
> }
> </style>
> <body>
> <h1>Colour Blend</h1>
>
> <p>
> Here is a mix of the two colours you specified:
> </p>
> <div id="blend">
>
> <div class="colourblock" style="background-color:
rgb(100.0%,10.0%,10.0%)">
> </div>
> <div class="colourblock" style="background-color:
rgb(100.0%,20.0%,20.0%)">
> </div>
> <div class="colourblock" style="background-color:
rgb(100.0%,30.0%,30.0%)">
> </div>
> <div class="colourblock" style="background-color:
rgb(100.0%,40.0%,40.0%)">
> </div>
> <div class="colourblock" style="background-color:
rgb(100.0%,50.0%,50.0%)">
> </div>
> <div class="colourblock" style="background-color:
rgb(100.0%,60.0%,60.0%)">
> </div>
> <div class="colourblock" style="background-color:
rgb(100.0%,70.0%,70.0%)">
> </div>
> <div class="colourblock" style="background-color:
rgb(100.0%,80.0%,80.0%)">
> </div>
> <div class="colourblock" style="background-color:
rgb(100.0%,90.0%,90.0%)">
> </div>
> <div class="colourblock" style="background-color:
> rgb(100.0%,100.0%,100.0%)"> </div>
>
> </div>
>
> </body>
> </html>"""
>
>
>
>
>
>

```