User:Dave Young/Thematic Project 1: Bits and Pieces: Difference between revisions
Dave Young (talk | contribs) (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...") |
|||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
=Computata Miscellanea= | |||
Places for homeless code snippets from the thematic project seminars and workshops. | Places for homeless code snippets from the thematic project seminars and workshops. | ||
===Script for Literal Draw/SVGs etc | ==Review Generator v0.01== | ||
Places pixels based on an ascii grid template. | Built in Nicolas Maleve's thematic project workshop. More information available [http://pzwart3.wdka.hro.nl/wiki/Networked_Media_Sampler/Based_on_a_true_story/even_better_than_the_best_group here] Below is the php code that shuffles the lines of the textfile and prints them to the webpage. | ||
<source lang="php"> | |||
<?php | |||
$goodlines = file('good.txt'); //the 'good' text file to read from | |||
shuffle($goodlines); //randomise array order | |||
$badlines = file('bad.txt'); | |||
shuffle($badlines); | |||
$numLines = rand(1, 8); //random number of sentences in review - min 1, max 8 sentences | |||
for ($i=0; $i<$numLines; $i++){ | |||
$currline = $goodlines[$i]; //store the current line $currline | |||
if(preg_match("*name*", $currline)){ //if *name* is found, insert the form element 'name' | |||
$currline = preg_replace("*name*", htmlspecialchars($_POST['name']), $currline); | |||
} | |||
if(preg_match("*city*", $currline)){ //if *city* is found, insert form element 'city' | |||
$currline = preg_replace("*city*", htmlspecialchars($_POST['city']), $currline); | |||
} | |||
echo $currline; //print edited $currline | |||
} | |||
?> | |||
</source> | |||
==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 [String], a starting x [int], and y [int] argument, a pixel size [int], and an outputfile_name.txt [string]. | |||
<pre> | <pre> | ||
Frog in a Boat | |||
-------------------------------------------------------------- | -------------------------------------------------------------- | ||
----------------------------XXXX----- | ----------------------------XXXX-----I'm fucking wrecked!----- | ||
--------------------------XXXX-XX-- | --------------------------XXXX-XX--/-------------------------- | ||
------------------------XXXXXXXXX----------------------------- | ------------------------XXXXXXXXX----------------------------- | ||
-----------------------XXXXXXXXXXXX----XX--------------------- | -----------------------XXXXXXXXXXXX----XX--------------------- | ||
Line 23: | Line 51: | ||
---------------------------XX--------------------------------- | ---------------------------XX--------------------------------- | ||
-------------------------XXXX--------------------------------- | -------------------------XXXX--------------------------------- | ||
</pre> | |||
<pre> | |||
Frog at a Bar | |||
----------------------------------------------- | |||
-------------------------------GIMME BEER!----- | |||
-----------------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------------------ | |||
----------------------------------------------- | |||
</pre> | |||
<pre> | |||
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------------------ | |||
</pre> | </pre> | ||
Line 38: | Line 108: | ||
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 58: | Line 128: | ||
thegrid.close() | thegrid.close() | ||
output.close()</ | output.close() | ||
</source> |
Latest revision as of 17:08, 13 December 2011
Computata Miscellanea
Places for homeless code snippets from the thematic project seminars and workshops.
Review Generator v0.01
Built in Nicolas Maleve's thematic project workshop. More information available here Below is the php code that shuffles the lines of the textfile and prints them to the webpage.
<?php
$goodlines = file('good.txt'); //the 'good' text file to read from
shuffle($goodlines); //randomise array order
$badlines = file('bad.txt');
shuffle($badlines);
$numLines = rand(1, 8); //random number of sentences in review - min 1, max 8 sentences
for ($i=0; $i<$numLines; $i++){
$currline = $goodlines[$i]; //store the current line $currline
if(preg_match("*name*", $currline)){ //if *name* is found, insert the form element 'name'
$currline = preg_replace("*name*", htmlspecialchars($_POST['name']), $currline);
}
if(preg_match("*city*", $currline)){ //if *city* is found, insert form element 'city'
$currline = preg_replace("*city*", htmlspecialchars($_POST['city']), $currline);
}
echo $currline; //print edited $currline
}
?>
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 [String], a starting x [int], and y [int] argument, a pixel size [int], and an outputfile_name.txt [string].
Frog in a Boat -------------------------------------------------------------- ----------------------------XXXX-----I'm fucking wrecked!----- --------------------------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 ----------------------------------------------- -------------------------------GIMME BEER!----- -----------------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------------------
#!/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()