User:Dave Young/Computata Miscellanea: txt-to-svg.py: Difference between revisions
Dave Young (talk | contribs) |
Dave Young (talk | contribs) |
||
Line 1: | Line 1: | ||
[[Category: Cookbook]] | [[Category: Cookbook]] | ||
=txt-to-svg.py= | |||
This script is a development of previous experiments in the last OSP workshop with using python to generate Literal Draw code, although in this version it bypasses the literal draw application in favour of directly producing an svg file that is viewable in a browser or can be edited in Inkscape. To draw with the script, you make a .txt file and draw uppercase 'X' characters where you want a square pixel to be drawn, any other character denotes a blank space. | This script is a development of previous experiments in the last OSP workshop with using python to generate Literal Draw code, although in this version it bypasses the literal draw application in favour of directly producing an svg file that is viewable in a browser or can be edited in Inkscape. To draw with the script, you make a .txt file and draw uppercase 'X' characters where you want a square pixel to be drawn, any other character denotes a blank space. | ||
==A Naff Logo== | |||
Here is a naff logo built with txt-to-svg and inspired by MicroProse logo from the 80s/90s (they made some pretty serious pc games such as X-Com and Pizza Tycoon). | Here is a naff logo built with txt-to-svg and inspired by MicroProse logo from the 80s/90s (they made some pretty serious pc games such as X-Com and Pizza Tycoon). | ||
[[File:txttosvg.svg]] | [[File:txttosvg.svg]] | ||
Line 36: | Line 36: | ||
==Code== | |||
The scripts takes three arguments: a textfile that functions as a grid-template for what is to be drawn, an outputfilename.svg, and the size of each "pixel" in the drawing. | The scripts takes three arguments: a textfile that functions as a grid-template for what is to be drawn, an outputfilename.svg, and the size of each "pixel" in the drawing. |
Revision as of 21:56, 13 December 2011
txt-to-svg.py
This script is a development of previous experiments in the last OSP workshop with using python to generate Literal Draw code, although in this version it bypasses the literal draw application in favour of directly producing an svg file that is viewable in a browser or can be edited in Inkscape. To draw with the script, you make a .txt file and draw uppercase 'X' characters where you want a square pixel to be drawn, any other character denotes a blank space.
A Naff Logo
Here is a naff logo built with txt-to-svg and inspired by MicroProse logo from the 80s/90s (they made some pretty serious pc games such as X-Com and Pizza Tycoon).
And here is the txt file that generated it. Please use the code and do something more interesting with it.
------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------- --------------------------------------------XXXXXXXXXXXXX---------------------------------------------- ----XXXXXXXXXXXXXXX-----------------------XXXXXXXXXXXXXXXX--------------------------------------------- ---XXXXXXXXXXXXXXX-----------------------XXXX----------XXX--------------------------------------------- ---------XXX----------------------------XXXX----------XXX---------------------------------------------- ---------XXX----------------------------------------XXXX-----------XXXXXX------------------------------ --------XXX----XXXXXXXXXX-----XXXXXXXXXXXXXXXX-----XXXX-----------XXXXXXXXX---------------------------- --------XXX---XXXXXXXX-XXX---XXXXXXXXXXXXXXXX----XXXXX-----------XXX----XXX-XXXXXXXXXXXXXXXXXXXXXXXX--- -------XXX----XXX-------XXX-XXX-----XXX--------XXXXXX-----------XXX------------------------------------ -------XXX---XXXXXX------XXXXX------XXX-------XXXXX-------------XXXX-------XXXX----XXXX--XXXXXXXX------ ------XXX----XXX--------XXX-XXX----XXX-------XXXX----------------XXXXXXXX---XXX----XXX--XXXXXXXXXX----- ------XXX---XXXXXXXX---XXX---XXX---XXX----XXXXXX----------------------XXXX--XXX---XXX--XXX------------- -----XXX----XXXXXXX---XXX-----XXX-XXX----XXXXXXXXXXXXXXXXXXXXX--------XXXX--XXX--XXX--XXX----XXXX------ -----XXX-----------------------XXXXXX--XXXXXXXXXXXXXXXXXXXXXX--XXX---XXXX---XXX-XXX--XXX------XX------- ---------------------------------------------------------------XXXXXXXXX----XXXXXX----XXXXXXXXX-------- ----XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--XXXXXX------XXXX-------XXXXXXX--------- ------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------
Code
The scripts takes three arguments: a textfile that functions as a grid-template for what is to be drawn, an outputfilename.svg, and the size of each "pixel" in the drawing.