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

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 1: Line 1:
Prints a square with a colour determined by a given longitude number.
Things to do next:
* Do something interesting with the numbers
<source lang=python>
<source lang=python>


Line 10: Line 15:
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"

Revision as of 15:21, 30 November 2011

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

Things to do next:

  • Do something interesting with the numbers
#!/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>"""