Tartans work and possible simplification

This commit is contained in:
Neale Pickett 2009-11-13 23:41:58 -06:00
parent ec72794f6e
commit 3da2681f24
12 changed files with 45 additions and 82 deletions

View File

@ -22,6 +22,8 @@ pre {
.figure { .figure {
float: right; float: right;
padding: 0.5em; padding: 0.25em;
margin: 0.5em;
font-size: small; font-size: small;
border: solid black 1px;
} }

View File

@ -2,11 +2,15 @@ SubDir TOP tartans ;
TARTAN_TMPL = $(SUBDIR)/tartan.m4 ; TARTAN_TMPL = $(SUBDIR)/tartan.m4 ;
TARTANTOMDWN = $(SUBDIR)/tartantomdwn ; TARTANTOMDWN = $(SUBDIR)/tartantomdwn ;
LSTARTANS = $(SUBDIR)/lstartans ;
LOOM = $(SUBDIR)/loom.py ; LOOM = $(SUBDIR)/loom.py ;
rule Tartan { rule Tartan {
local tartans = [ FGristFiles $(1:S=.tartan) ] ; local tartans = [ FGristFiles $(1:S=.tartan) ] ;
DIRLIST on [ FGristFiles index.mdwn ] = $(LSTARTANS) ;
AutoIndex index.mdwn : index.head.mdwn : $(1:S=.tartan) ;
for t in $(tartans) { for t in $(tartans) {
local png = $(t:S=.png:D=img:G=) ; local png = $(t:S=.png:D=img:G=) ;
local mdwn = $(t:S=.mdwn) ; local mdwn = $(t:S=.mdwn) ;
@ -32,8 +36,10 @@ rule TartanToPng {
SEARCH on $(2) = $(SEARCH_SOURCE) ; SEARCH on $(2) = $(SEARCH_SOURCE) ;
} }
actions TartanToMdwn { actions TartanToMdwn {
$(TARTANTOMDWN) $(1:S=) < $(2) > $(1) $(TARTANTOMDWN) $(1:S=.png:D=img) $(TARTAN_TMPL) < $(2) > $(1)
} }
actions TartanToPng { actions TartanToPng {

View File

@ -3,7 +3,7 @@ Sett: R4 G24 B4 G10 B36 W6 R4 W4
Created by Ralph Stevenson Jr and Charles Hargis in 2005 for the city's Created by Ralph Stevenson Jr and Charles Hargis in 2005 for the city's
tricentennial anniversary (1706-2006). It is similar in design to the tricentennial anniversary (1706-2006). It is similar in design to the
[New Mexico tartan](nm), with a little less green, and white instead of [New Mexico tartan](nm.html), with a little less green, and white instead of
yellow, with a thicker center band. yellow, with a thicker center band.
[Bally Dun Celtic Treasures](http://www.ballydun.com/) sells this tartan. [Bally Dun Celtic Treasures](http://www.ballydun.com/) sells this tartan.

View File

@ -1,4 +1,4 @@
Name: Black Watch Name: Black Watch
Sett: B22 BK2 B2 BK2 B2 BK16 G16 BK2 G16 BK16 B16 BK2 B2BK2 G10 BK8 DB9 BK1 DB1 Sett: B22 BK2 B2 BK2 B2 BK16 G16 BK2 G16 BK16 B16 BK2 B2 BK2 G10 BK8 DB9 BK1 DB1
A standard. A standard.

View File

@ -1,88 +1,38 @@
#! /usr/bin/python #! /usr/bin/python
import cgitb; cgitb.enable() import cgitb; cgitb.enable()
import htmltmpl
import loom import loom
import re
import sys
import cgi import cgi
import os
import rfc822
import urllib import urllib
import cStringIO as StringIO import os
import sys
var_re = re.compile('\$(\w+|{\w+})')
def fill_template(tmpl, **keywds):
def repl(match):
var = match.group(0)[1:]
var = var.strip('{}')
return keywds[var]
return var_re.sub(repl, tmpl)
def serve(s, c_t):
o = ('Content-type: %s\r\nContent-length: %d\r\n\r\n%s' %
(c_t, len(s), s))
sys.stdout.write(o)
f = cgi.FieldStorage() f = cgi.FieldStorage()
s = f.getfirst('sett') s = f.getfirst('sett')
if s: if s:
print('Content-type: image/png')
print('')
sett = loom.str_to_sett(s) sett = loom.str_to_sett(s)
l = loom.tartan(sett) l = loom.tartan(sett)
p = StringIO.StringIO() l.png(sys.stdout)
l.png(p)
serve(p.getvalue(), 'image/png')
else: else:
manager = htmltmpl.TemplateManager(precompile=0) t = f.getfirst('t', 'Unknown')
tmpl = manager.prepare('/home/neale/lib/wiki/templates/page.tmpl')
processor = htmltmpl.TemplateProcessor(html_escape=False)
t = os.environ.get('PATH_INFO', '').strip('/')
if not t:
t = f.getfirst('t', 'Unknown')
s = f.getfirst('s') s = f.getfirst('s')
if t and not s:
try:
m = rfc822.Message(file('%s.tartan' % t))
t = m.get('Title', t)
s = m.get('Sett')
except IOError:
pass
if not t or not s: if not t or not s:
# Default to Black Watch # Default to Black Watch
t = 'Black Watch' t = 'Black Watch'
s = ('B22 BK2 B2 BK2 B2 BK16 G16 BK2 G16 BK16 B16 BK2 B2' s = ('B22 BK2 B2 BK2 B2 BK16 G16 BK2 G16 BK16 B16 BK2 B2 '
'BK2 G10 BK8 DB9 BK1 DB1') 'BK2 G10 BK8 DB9 BK1 DB1')
s_st = s.replace(' ', '') s_ = s.replace(' ', '').replace('\n', '')
s_st = s_st.replace('\n' ,'')
content = ''' print('Content-type: text/html')
<ul style="background: white; float: right;"> print('')
<li><a href="design.cgi?sett=%(sett_compressed)s">image only</a></li> sys.stdout.flush()
<li><a href="/~neale/tartans">More tartans</a></li> content = ('Name: %s\nSett: %s\n' % (t, s))
</ul> png = 'design.cgi?sett=%s' % urllib.quote(s_)
cvt = os.popen('./tartantomdwn %s tartan.m4 | ../mdwntohtml ../template.xml' % (png,),
<h2>woozle.org tartan designer</h2> 'w')
<form action="design" style="padding: 10px;"> cvt.write(content)
<input name="t" value="%(tartan)s" /> cvt.close()
<textarea name="s" rows="3" cols="40">%(sett)s</textarea> <br />
<input type="submit" value="Generate" />
</form>
<div style="background: url(design.cgi?sett=%(sett_compressed)s);
height: 400px;
border: solid black 40px;">
</div>
''' % {'tartan': t,
'sett': s,
'sett_compressed': urllib.quote(s_st)}
processor.set('title', t)
processor.set('content', content)
page = processor.process(tmpl)
serve(page, 'text/html')

View File

@ -6,7 +6,7 @@ description.
<div class="figure"> <div class="figure">
<img src="img/nmloe.png" alt="tartan image" /> <img src="img/nmloe.png" alt="tartan image" />
<br /> <br />
<a href="nmloe"> <a href="nmloe.html">
New Mexico Land Of Enchantment New Mexico Land Of Enchantment
</a> </a>
<br /> <br />
@ -20,3 +20,4 @@ are some tartans I've made with it.
If you have one you'd like to contribute to my database, or would like If you have one you'd like to contribute to my database, or would like
the code that generates this stuff, feel free to [email the code that generates this stuff, feel free to [email
me](mailto:neale-tartan@woozle.org). me](mailto:neale-tartan@woozle.org).

View File

@ -1,5 +1,7 @@
#! /bin/sh #! /bin/sh
cat $1; shift
for i in "$@"; do for i in "$@"; do
base=$(basename $i .tartan) base=$(basename $i .tartan)
name=$(awk -F': ' '(/^Name:/) {print $2; exit;}' $i) name=$(awk -F': ' '(/^Name:/) {print $2; exit;}' $i)

BIN
tartans/nm-proc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

View File

@ -1,9 +1,9 @@
Name: New Mexico Name: New Mexico
Sett: R4 G24 B4 G16 B36 Y8 R4 Y4 Sett: R4 G24 B4 G16 B36 Y8 R4 Y4
Designed by Ralph Stevenson Jr, [officially recognized in 2003](nm-proc) Designed by Ralph Stevenson Jr, [officially recognized in 2003](nm-proc.png)
by the Secretary of State. It is similar in design to the [Albuquerque by the Secretary of State. It is similar in design to the [Albuquerque
tartan](albuquerque). I bought a scarf of this plaid from tartan](albuquerque.html). I bought a scarf of this plaid from
Mr. Stevenson; it came with a photocopy of the tartan registration and a Mr. Stevenson; it came with a photocopy of the tartan registration and a
few other documents. few other documents.

View File

@ -1,20 +1,21 @@
Title: TARTAN Tartan Title: TARTAN Tartan
divert(1) <div style="background: url(IMAGE);
<div style="background: url(img/BASE.png); height: 300px;
height: 400px; border: solid black 10px;
border: solid black 40px;
clear: both;"> clear: both;">
</div> </div>
divert(1)
I place this image in the public domain, in the hope that it will I place this image in the public domain, in the hope that it will
increase interest in tartans and tartan design. increase interest in tartans and tartan design.
<form action="design.cgi"> <form action="design.cgi">
<fieldset> <fieldset>
<legend>Tartan Designer</legend> <legend>Tartan Designer</legend>
<label for="t">Name:</label> <input name="t" value="TARTAN" /> <br/> <label for="t">Name:</label> <input name="t" id="t" value="TARTAN" /> <br/>
<label for="s">Sett:</label> <input name="s" value="SETT" /> <br/> <label for="s">Sett:</label> <input name="s" id="s" value="SETT" style="width: 90%" /> <br/>
<input type="submit" value="Design" /> <input type="submit" value="Design" />
</fieldset> </fieldset>
</form> </form>

View File

@ -18,5 +18,5 @@ header () {
} }
eval $(header) eval $(header)
m4 -DTARTAN="$TARTAN" -DSETT="$SETT" -DBASE="$1" tartan.m4 - m4 -DTARTAN="$TARTAN" -DSETT="$SETT" -DIMAGE="$1" $2 -

View File

@ -3,6 +3,7 @@ Title: Toys
Here is some various junk I've done. Maybe you'll find it amusing. Here is some various junk I've done. Maybe you'll find it amusing.
Maybe you'll just wonder why I spend so much time on this garbage. Maybe you'll just wonder why I spend so much time on this garbage.
* I like [tartans](../tartans/).
* Play [a fun game](fungame.html)! * Play [a fun game](fungame.html)!
* If you need to write someone a letter but really don't want to, try my * If you need to write someone a letter but really don't want to, try my
[smalltalk generator](smalltalk.cgi). [smalltalk generator](smalltalk.cgi).