User:Eleanorg/Thematic1.1/Manipulate Longitude 1

From XPUB & Lens-Based wiki

Prints a square with a colour determined by a given longitude number.

Things to do next:

  • Find a more sophisticated way to manipulate the numbers into something interesting
  • Plug into live longitude data online
#!/usr/bin/python
#-*- coding:utf-8 -*-


# first stab at turning a longitude position into a hexadecimal colour, using lorem longitude no.
# numbers actually need some manipulation so that colour differences are visible - split them?

import re

longitude = str(002.9999)                        # must be a string for regex to work
longint = re.sub("\.", "", longitude)            # removes decimal point, leaving 5 digit number
hexcode = "#0" + longint                         # adds a digit, making a hex colour code

print "Content-Type: text/html"
print
print """
  <html>
    <body>
       <div style="width: 300px; height: 300px; background-color: """ + hexcode + """;">
         <p>""" + hexcode + """</p>
       </div>
    </body>
  </html>"""