mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Add Dominosa printout support.
[originally from svn r6094]
This commit is contained in:
39
print.py
39
print.py
@ -13,8 +13,8 @@
|
|||||||
# print.py <game-name> <format>
|
# print.py <game-name> <format>
|
||||||
#
|
#
|
||||||
# <game-name> is one of `rect', `rectangles', `pattern', `solo',
|
# <game-name> is one of `rect', `rectangles', `pattern', `solo',
|
||||||
# `net'. <format> is two numbers separated by an x: `2x3', for
|
# `net', `dominosa'. <format> is two numbers separated by an x:
|
||||||
# example, means two columns by three rows.
|
# `2x3', for example, means two columns by three rows.
|
||||||
#
|
#
|
||||||
# The program will then read game IDs from stdin until it sees EOF,
|
# The program will then read game IDs from stdin until it sees EOF,
|
||||||
# and generate as many PostScript pages on stdout as it needs.
|
# and generate as many PostScript pages on stdout as it needs.
|
||||||
@ -333,12 +333,45 @@ def solo_format(s):
|
|||||||
((x+0.5)*gridpitch, (cr-y-0.5)*gridpitch, s))
|
((x+0.5)*gridpitch, (cr-y-0.5)*gridpitch, s))
|
||||||
return ret.coords, ret.s
|
return ret.coords, ret.s
|
||||||
|
|
||||||
|
def dominosa_format(s):
|
||||||
|
ret = Holder()
|
||||||
|
ret.s = ""
|
||||||
|
params, seed = string.split(s, ":")
|
||||||
|
n = string.atoi(params)
|
||||||
|
w = n+2
|
||||||
|
h = n+1
|
||||||
|
grid = []
|
||||||
|
while len(seed) > 0:
|
||||||
|
if seed[0] == '[': # XXX
|
||||||
|
d, seed = string.split(seed[1:], "]")
|
||||||
|
grid.append(string.atoi(d))
|
||||||
|
else:
|
||||||
|
assert seed[0] in string.digits
|
||||||
|
grid.append(string.atoi(seed[0:1]))
|
||||||
|
seed = seed[1:]
|
||||||
|
assert w*h == len(grid)
|
||||||
|
# I'm going to arbitrarily choose to use 9pt text for the
|
||||||
|
# numbers, and a 16pt grid pitch.
|
||||||
|
textht = 9
|
||||||
|
gridpitch = 16
|
||||||
|
pw = gridpitch * w
|
||||||
|
ph = gridpitch * h
|
||||||
|
psprint(ret, "/Helvetica findfont %g scalefont setfont" % textht)
|
||||||
|
ret.coords = (pw/2, pw/2, ph/2, ph/2)
|
||||||
|
psprint(ret, "%g %g translate" % (-ret.coords[0], -ret.coords[2]))
|
||||||
|
for y in xrange(h):
|
||||||
|
for x in xrange(w):
|
||||||
|
psprint(ret, "%g %g (%d) ctshow" % \
|
||||||
|
((x+0.5)*gridpitch, (h-y-0.5)*gridpitch, grid[y*w+x]))
|
||||||
|
return ret.coords, ret.s
|
||||||
|
|
||||||
formatters = {
|
formatters = {
|
||||||
"net": net_format,
|
"net": net_format,
|
||||||
"rect": rect_format,
|
"rect": rect_format,
|
||||||
"rectangles": rect_format,
|
"rectangles": rect_format,
|
||||||
"pattern": pattern_format,
|
"pattern": pattern_format,
|
||||||
"solo": solo_format
|
"solo": solo_format,
|
||||||
|
"dominosa": dominosa_format
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) < 3:
|
||||||
|
Reference in New Issue
Block a user