User:Silviolorusso/ipmosaic: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
'''IP Mosaic''' | '''IP Mosaic''' | ||
[http://pzwart3.wdka.hro.nl/~slorusso/cgi-bin/ipmosaic.cgi IP Mosaic] | |||
'''What''' | '''What''' | ||
A webpage that collects little squares whose colour is based on the IP Address of the visitor. | A webpage that collects little squares whose colour is based on the IP Address of the visitor. | ||
[[File:ipmosaic.png]] | |||
'''Code''' | '''Code''' |
Revision as of 21:36, 4 November 2011
IP Mosaic
What
A webpage that collects little squares whose colour is based on the IP Address of the visitor.
Code
#!/usr/bin/python
import os
print "Content-type:text/html; charset=utf-8"
print
#retrieve the IP Address
ipad = os.environ['REMOTE_ADDR']
#split into 4 values
ipad = ipad.split('.')
#obtain a float value for the alpha
ipadalpha = float(ipad[3])
#print the taxel
div = """
<div style="width:10px; height:10px; float:left; background:rgba({0}, {1}, {2}, {3})" >
</div>
""".format(ipad[0], ipad[1], ipad[2], (ipadalpha/255))
#open the txt file and append div
divs = open('divs.txt','a')
divs.write(div)
#print head of the html
print """
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>IP Mosaic</title>
</head>
<body style="margin:0">
"""
divs = open('divs.txt','r')
print divs.read()
print "</body>"