X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/c3ea5dc791a92c7d2a6f9e1fc87e8e064b66cab3..de3b0e332712c81307a7800808b6d13d2c5cec93:/print.py diff --git a/print.py b/print.py index 5078abe..d6b27f5 100755 --- a/print.py +++ b/print.py @@ -13,8 +13,8 @@ # print.py # # is one of `rect', `rectangles', `pattern', `solo', -# `net'. is two numbers separated by an x: `2x3', for -# example, means two columns by three rows. +# `net', `dominosa'. is two numbers separated by an x: +# `2x3', for example, means two columns by three rows. # # The program will then read game IDs from stdin until it sees EOF, # and generate as many PostScript pages on stdout as it needs. @@ -123,6 +123,7 @@ def net_format(s): scale = 0.25 bigoffset = 0.25 smalloffset = 0.17 + squaresize = 0.25 # Set up coordinate system. pw = gridpitch * w ph = gridpitch * h @@ -185,16 +186,25 @@ def net_format(s): psprint(ret, "0 0 moveto %d %d lineto" % (dx, dy)) psprint(ret, "stroke") # Draw additional figures if desired. - if v == 13: - # T-pieces have a little circular blob where the lines join. - psprint(ret, "newpath 0 0 0.15 0 360 arc fill") - elif v == 1: + if v == 1: # Endpoints have a little empty square at the centre. - psprint(ret, "newpath 0.35 0.35 moveto 0 -0.7 rlineto") - psprint(ret, "-0.7 0 rlineto 0 0.7 rlineto closepath") - psprint(ret, "gsave 1 setgray fill grestore stroke") - # Clean up. + psprint(ret, "newpath %g %g moveto 0 -%g rlineto" % \ + (squaresize, squaresize, squaresize * 2)) + psprint(ret, "-%g 0 rlineto 0 %g rlineto closepath fill" % \ + (squaresize * 2, squaresize * 2)) + # Get back out of the centre section. psprint(ret, "grestore") + # Draw the endpoint square in large in the middle. + if v == 1: + psprint(ret, "gsave") + psprint(ret, "%g %g translate" % \ + ((x + 0.5) * gridpitch, (h - y - 0.5) * gridpitch)) + psprint(ret, "%g dup scale" % (float(gridpitch) / 2)) + psprint(ret, "newpath %g %g moveto 0 -%g rlineto" % \ + (squaresize, squaresize, squaresize * 2)) + psprint(ret, "-%g 0 rlineto 0 %g rlineto closepath fill" % \ + (squaresize * 2, squaresize * 2)) + psprint(ret, "grestore") return ret.coords, ret.s def pattern_format(s): @@ -323,12 +333,45 @@ def solo_format(s): ((x+0.5)*gridpitch, (cr-y-0.5)*gridpitch, 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 = { "net": net_format, "rect": rect_format, "rectangles": rect_format, "pattern": pattern_format, -"solo": solo_format +"solo": solo_format, +"dominosa": dominosa_format } if len(sys.argv) < 3: