User:Dave Young/Thematic Project 1: Bits and Pieces: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "==Computata Miscellanea== Places for homeless code snippets from the thematic project seminars and workshops. ===Script for Literal Draw/SVGs etc=== Places pixels based on an as...")
 
Line 5: Line 5:
Places pixels based on an ascii grid template.
Places pixels based on an ascii grid template.
<pre>
<pre>
Frog In A Boat
--------------------------------------------------------------
--------------------------------------------------------------
----------------------------XXXX------------------------------
----------------------------XXXX------------------------------

Revision as of 17:06, 6 December 2011

Computata Miscellanea

Places for homeless code snippets from the thematic project seminars and workshops.

Script for Literal Draw/SVGs etc

Places pixels based on an ascii grid template.

Frog In A Boat
--------------------------------------------------------------
----------------------------XXXX------------------------------
--------------------------XXXX-XX-----------------------------
------------------------XXXXXXXXX-----------------------------
-----------------------XXXXXXXXXXXX----XX---------------------
----------------------XXXXXXXXXXXXXXXXXX----------------------
XXX------------------XXXXXXXXXXX----XX---------------------XXX
XXXX----------------XXXXXXXXXXXX---XX---------------------XXXX
XXXXXXXXXXX---------XXXXXXXXXXXX--XX---------------XXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
----XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX----
--------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--------
-------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-------------
----------------------------XX--------------------------------
---------------------------XX---------------------------------
-------------------------XXXX---------------------------------

<source lang="python">

  1. !/usr/bin/python
  2. automates grid-based transformations
  3. Args: gridfile | commandfile | columnwidth | rowheight


import sys

thegrid = open(sys.argv[1]) #grid template - X = draw commands output = open(sys.argv[2], "w") #the outputted text to paste into

x = int(sys.argv[3]) y = int(sys.argv[4]) ox = x oy = y sz = 20

def commands(x, y, sz): cmd = "move {0} {1} \n line {2} {3} \n line {4} {5} \n line {6} {7} \n close\n\n".format(x, y, x+sz, y, x+sz, y+sz, x, y+sz) output.write(cmd)

for line in thegrid: ret=0 for char in line: x+=sz if char == str('X'): commands(x, y, sz) x=ox y+=sz

thegrid.close() output.close()</sourcecode>