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 {
float: right;
padding: 0.5em;
padding: 0.25em;
margin: 0.5em;
font-size: small;
border: solid black 1px;
}

View File

@ -2,11 +2,15 @@ SubDir TOP tartans ;
TARTAN_TMPL = $(SUBDIR)/tartan.m4 ;
TARTANTOMDWN = $(SUBDIR)/tartantomdwn ;
LSTARTANS = $(SUBDIR)/lstartans ;
LOOM = $(SUBDIR)/loom.py ;
rule 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) {
local png = $(t:S=.png:D=img:G=) ;
local mdwn = $(t:S=.mdwn) ;
@ -32,8 +36,10 @@ rule TartanToPng {
SEARCH on $(2) = $(SEARCH_SOURCE) ;
}
actions TartanToMdwn {
$(TARTANTOMDWN) $(1:S=) < $(2) > $(1)
$(TARTANTOMDWN) $(1:S=.png:D=img) $(TARTAN_TMPL) < $(2) > $(1)
}
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
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.
[Bally Dun Celtic Treasures](http://www.ballydun.com/) sells this tartan.

View File

@ -1,4 +1,4 @@
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.

View File

@ -1,88 +1,38 @@
#! /usr/bin/python
import cgitb; cgitb.enable()
import htmltmpl
import loom
import re
import sys
import cgi
import os
import rfc822
import urllib
import cStringIO as StringIO
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)
import os
import sys
f = cgi.FieldStorage()
s = f.getfirst('sett')
if s:
print('Content-type: image/png')
print('')
sett = loom.str_to_sett(s)
l = loom.tartan(sett)
p = StringIO.StringIO()
l.png(p)
serve(p.getvalue(), 'image/png')
l.png(sys.stdout)
else:
manager = htmltmpl.TemplateManager(precompile=0)
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')
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:
# Default to 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')
s_st = s.replace(' ', '')
s_st = s_st.replace('\n' ,'')
s_ = s.replace(' ', '').replace('\n', '')
content = '''
<ul style="background: white; float: right;">
<li><a href="design.cgi?sett=%(sett_compressed)s">image only</a></li>
<li><a href="/~neale/tartans">More tartans</a></li>
</ul>
<h2>woozle.org tartan designer</h2>
<form action="design" style="padding: 10px;">
<input name="t" value="%(tartan)s" />
<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')
print('Content-type: text/html')
print('')
sys.stdout.flush()
content = ('Name: %s\nSett: %s\n' % (t, s))
png = 'design.cgi?sett=%s' % urllib.quote(s_)
cvt = os.popen('./tartantomdwn %s tartan.m4 | ../mdwntohtml ../template.xml' % (png,),
'w')
cvt.write(content)
cvt.close()

View File

@ -6,7 +6,7 @@ description.
<div class="figure">
<img src="img/nmloe.png" alt="tartan image" />
<br />
<a href="nmloe">
<a href="nmloe.html">
New Mexico Land Of Enchantment
</a>
<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
the code that generates this stuff, feel free to [email
me](mailto:neale-tartan@woozle.org).

View File

@ -1,5 +1,7 @@
#! /bin/sh
cat $1; shift
for i in "$@"; do
base=$(basename $i .tartan)
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
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
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
few other documents.

View File

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

View File

@ -18,5 +18,5 @@ 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.
Maybe you'll just wonder why I spend so much time on this garbage.
* I like [tartans](../tartans/).
* Play [a fun game](fungame.html)!
* If you need to write someone a letter but really don't want to, try my
[smalltalk generator](smalltalk.cgi).