User:Lieven Van Speybroeck/Prototyping/9-Constellate me: Difference between revisions

From XPUB & Lens-Based wiki
mNo edit summary
mNo edit summary
Line 92: Line 92:
circle = """<circle cx="{0}%" cy="{1}%" r="{2}" fill="{3}" stroke="none" style="opacity:{4};" />"""
circle = """<circle cx="{0}%" cy="{1}%" r="{2}" fill="{3}" stroke="none" style="opacity:{4};" />"""
line = """<line x1="{0}%" y1="{1}%" x2="{2}%" y2="{3}%" stroke="#ff00ff" stroke-width="0.1%" />"""
line = """<line x1="{0}%" y1="{1}%" x2="{2}%" y2="{3}%" stroke="#ff00ff" stroke-width="0.1%" />"""
 
text = """<text x="{0}%" y="{1}%" fill="#ff00ff" font-family="Courier" font-size="13" text-anchor="middle">{2}</text>"""
text = """<text x="{0}%" y="{1}%" fill="ff00ff" font-family="Courier" font-size="13" text-anchor="middle">{2}</text>"""


for x in range(0,800):
for x in range(0,800):

Revision as of 21:49, 29 October 2011

Star Vector Graphics

Find out what your real constellation is...

examples

constellate(.py)

#!/usr/bin/python
import sys, string, random

alphabet = string.lowercase
name = sys.argv[1]
clean = sys.argv[1].replace(" ",'')
try:
	characters = list(clean.lower());
	length = len(sys.argv[1]);
	f = open('constellations/'+name+'.svg', 'w')

	f.write("""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
	<!-- Created with Inkscape (http://www.inkscape.org/) -->

	<svg
	   xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:cc="http://creativecommons.org/ns#"
	   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	   xmlns:svg="http://www.w3.org/2000/svg"
	   xmlns="http://www.w3.org/2000/svg"
	   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
	   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
	   width="100%"
	   height="100%"
	   id="svg3040"
	   version="1.1"
	   inkscape:version="0.48.1 r9760"
	   sodipodi:docname="New document 3">
	  <defs
	     id="defs3042" />
	  <sodipodi:namedview
	     id="base"
	     pagecolor="#ffffff"
	     bordercolor="#666666"
	     borderopacity="1.0"
	     inkscape:pageopacity="0.0"
	     inkscape:pageshadow="2"
	     inkscape:zoom="1.979899"
	     inkscape:cx="335.42751"
	     inkscape:cy="427.91605"
	     inkscape:document-units="px"
	     inkscape:current-layer="layer2"
	     showgrid="false"
	     inkscape:snap-global="false"
	     inkscape:window-width="1918"
	     inkscape:window-height="1177"
	     inkscape:window-x="0"
	     inkscape:window-y="21"
	     inkscape:window-maximized="0" />
	  <metadata
	     id="metadata3045">
	    <rdf:RDF>
	      <cc:Work
		 rdf:about="">
		<dc:format>image/svg+xml</dc:format>
		<dc:type
		   rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
		<dc:title></dc:title>
	      </cc:Work>
	    </rdf:RDF>
	  </metadata>
	  <g
	     inkscape:label="sky"
	     inkscape:groupmode="layer"
	     id="layer1"
	     sodipodi:insensitive="true">
	    <rect
	       style="fill:#000000;fill-opacity:1;stroke:none"
	       id="rect3048"
	       width="100%"
	       height="100%" />
	  </g>
	  <g
	     inkscape:groupmode="layer"
	     id="layer2"
	     inkscape:label="constellation">""")

	circle = """<circle cx="{0}%" cy="{1}%" r="{2}" fill="{3}" stroke="none" style="opacity:{4};" />"""
	line = """<line x1="{0}%" y1="{1}%" x2="{2}%" y2="{3}%" stroke="#ff00ff" stroke-width="0.1%" />"""
	text = """<text x="{0}%" y="{1}%" fill="#ff00ff" font-family="Courier" font-size="13" text-anchor="middle">{2}</text>"""

	for x in range(0,800):
		f.write(circle.format(random.random()*100, random.random()*100, random.randint(2,5), 'grey', random.random()))

	x = 0
	for n in characters:
		pos = ((alphabet.index(n))+1)
		if 1 <= pos <= 4:
			y1 = 20
			x1 = (pos*10)+20
		elif 5 <= pos <= 8:
			y1 = 30 
			x1 = ((pos-4)*10)+10
		elif 9 <= pos <= 12:
			y1 = 35
			x1 = ((pos-8)*10)+27
		elif 13 <= pos <= 16:
			y1 = 45
			x1 = ((pos-12)*10)+18
		elif 17 <= pos <= 20:
			y1 = 53
			x1 = ((pos-16)*10)+12
		elif 21 <= pos <= 24:
			y1 = 77
			x1 = ((pos-20)*10)+36
		elif 25 <= pos <= 26:
			y1 = 84
			x1 = ((pos-24)*10)+23
		f.write(circle.format(x1, y1, random.randint(2,6), 'white',1))
		if x != 0:
			f.write(line.format(x2, y2, x1, y1))
		else:
			textx = x1
			texty = y1-2
		x2 = x1
		y2 = y1
		x=1
	f.write(text.format(textx, texty, name))
	f.write("""
	</g>
	</svg>""")
except:
	print '\n!-------------------------------!\nOnly characters from a-z allowed\n!-------------------------------!\n'

run

  • $ chmod +x constellate
  • $ cp constellate /usr/local/bin
  • $ constellate 'Whatever you want to write in the stars'