User:Eleanorg/Thematic1.1/Manipulate Longitude 1: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
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
<source lang=python>
<source lang=python>


Line 10: Line 16:
import re
import re


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


print "Content-Type: text/html"
print "Content-Type: text/html"

Latest revision as of 15:22, 30 November 2011

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>"""