User:Laura Macchini/prototyping/Oh to be in need of glasses: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 5: Line 5:
In stead of letters it has tiny rectangles; to each letter of the alphabet is associated a value of gray,
In stead of letters it has tiny rectangles; to each letter of the alphabet is associated a value of gray,
if you are in need of glasses it sort of looks like tiny text.
if you are in need of glasses it sort of looks like tiny text.
[[File:Letter.svg]]


<source lang="python">
<source lang="python">

Revision as of 11:53, 27 October 2011

A generation of Soldiers seemed like a lame experiment and I couldn't sleep. Tossing and turning in the bed I dreamt of this -->

In stead of letters it has tiny rectangles; to each letter of the alphabet is associated a value of gray, if you are in need of glasses it sort of looks like tiny text.


Letter.svg

import random, string, math
string.ascii_lowercase

cTab = dict()
alphabet = string.ascii_lowercase

for i in range (0,len(alphabet)):
	delta = int(math.floor(255/len(alphabet)))
	cTab[alphabet[i]] = i*delta

f = open ("soldier.txt", "r" )
s = f.read()
words = s.split()
dW = 8
dL = 16
punctuation = ['.',',','?']

#global
cX = 40
cY = 30


print '''<svg xmlns="http://www.w3.org/2000/svg" version="1.1">'''

def rectangle(i,char):
	global cX
	global cY
	cX += dW
	cVal = cTab[char]
#	print cVal
	print'''
	  <rect x="{0}" y="{1}" width="{2}" height="{3}"
	  style="fill:rgb({4},{5},{6})"> <animate attributeName="opacity" from="1" to="0"
	begin="click" dur="2s" fill="restore" /> </rect>'''.format(cX,cY,dW,dL,cVal,cVal,cVal)

def newLine():
	global cX
	global cY
	cY += dW*5
	cX = 40


for i in range(0,len(words)):
	word = words[i]
	for char in word:
		if word in punctuation:
			newLine()
		else:
			if char in cTab:
				char = char.lower()
				rectangle(i,char)
#				print char,
#	print " ",

print '''</svg> '''