User:Dave Young/Thematic Project 1: Bits and Pieces: Difference between revisions
Dave Young (talk | contribs) |
Dave Young (talk | contribs) |
||
Line 3: | Line 3: | ||
===Script for Literal Draw/SVGs etc=== | ===Script for Literal Draw/SVGs etc=== | ||
Places pixels based on an ascii grid template. | Places pixels based on an ascii grid template - an 'X' = a pixel relative to that point on the canvas, any other text character leaves a blank space. | ||
The script expects a grid.txt argument, an x and y argument, and an outputfile_name.txt. | |||
<pre> | <pre> | ||
Frog in a Boat | Frog in a Boat | ||
Line 63: | Line 64: | ||
----------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXX---------------- | ----------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXX---------------- | ||
------------------XXXXXXXXXXXXXXXXXXXXXXXXX------------------ | ------------------XXXXXXXXXXXXXXXXXXXXXXXXX------------------ | ||
--------------------XXX--------------XXX | --------------------XXX---------------XXX-------------------- | ||
--------------------XXX--------------XXX | --------------------XXX---------------XXX-------------------- | ||
--------------------XXX--------------XXX | --------------------XXX---------------XXX-------------------- | ||
------------------XXXXXXX----------XXXXXXX | ------------------XXXXXXX-----------XXXXXXX------------------ | ||
</pre> | </pre> | ||
<source lang="python"> | <source lang="python"> | ||
Line 80: | Line 81: | ||
output = open(sys.argv[2], "w") #the outputted text to paste into | output = open(sys.argv[2], "w") #the outputted text to paste into | ||
x = int(sys.argv[3]) | x = int(sys.argv[3]) #starting x point | ||
y = int(sys.argv[4]) | y = int(sys.argv[4]) #starting y point | ||
ox = x | ox = x | ||
oy = y | oy = y | ||
sz = | sz = int(sys.argv[5]) #the size of the rectangle | ||
def commands(x, y, sz): | 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) | 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) #a rectangle! | ||
output.write(cmd) | output.write(cmd) | ||
Line 100: | Line 101: | ||
thegrid.close() | thegrid.close() | ||
output.close()</sourcecode> | output.close() | ||
</sourcecode> |
Revision as of 16:13, 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 - an 'X' = a pixel relative to that point on the canvas, any other text character leaves a blank space. The script expects a grid.txt argument, an x and y argument, and an outputfile_name.txt.
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---------------------------------
Frog at a Bar ----------------------------------------------- ----------------------------------------------- -----------------XX----XX---------------------- -----------------X-XXXX-XX--------------------- -----------------XXXXXXXXXXX------------------- ----------------XXXXXXXXXXXXXX----------------- X--------------XXX-XXXXXXXX-XXX-------------XXX XX-------------XX--XXXXXXXX---XXX----------XXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ------------------XX------XX------------------- ------------------XX------XX------------------- ------------------XX------XX------------------- ------------------XX------XX------------------- -----------------XXX------XXX------------------ -----------------------------------------------
Frog 'Avin a Laugh ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------XXXXX----------------XXXXX----------------- ----------------XXX--XXX--------------XXX--XX---------------- X--------------XXXX--XXXXXXXXXXXXXXXXXXXX--XXX--------------X XX------------XXXXX--XXXXXXXXXXXXXXXXXXXX--XXXX------------XX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XX------------XXXXXX--XXXXXXXXXXXXXXXXXX--XXXXX------------XX X--------------XXXXX----------------------XXXX--------------X ----------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXX---------------- ------------------XXXXXXXXXXXXXXXXXXXXXXXXX------------------ --------------------XXX---------------XXX-------------------- --------------------XXX---------------XXX-------------------- --------------------XXX---------------XXX-------------------- ------------------XXXXXXX-----------XXXXXXX------------------
<source lang="python">
- !/usr/bin/python
- automates grid-based transformations
- 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]) #starting x point y = int(sys.argv[4]) #starting y point ox = x oy = y sz = int(sys.argv[5]) #the size of the rectangle
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) #a rectangle! 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>