diff options
author | Walter Bender <walter@sugarlabs.org> | 2010-07-20 11:30:03 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2010-07-20 11:30:03 (GMT) |
commit | c9b84ccaef027ae3b845f5270d3775f03f1acbae (patch) | |
tree | bbf2b5e322654387830efb97e0514bf31b64012b | |
parent | ddbb8199a4e20c7658b57450b3f2e8811b52d481 (diff) |
generate pieces for 2nd puzzle
-rw-r--r-- | constants.py | 35 | ||||
-rwxr-xr-x | gentiles.py | 69 |
2 files changed, 103 insertions, 1 deletions
diff --git a/constants.py b/constants.py new file mode 100644 index 0000000..8ea6eb7 --- /dev/null +++ b/constants.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +#Copyright (c) 2009,10 Walter Bender + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +R = "#ff0000" +Y = "#ffff00" +B = "#0000ff" +G = "#00ff00" + +C = [[Y, B, Y, R], [R, Y, Y, R], [R, R, Y, R], [R, R, R, R], [B, B, B, Y], [Y, B, Y, Y], + [R, B, R, R], [Y, Y, Y, Y], [Y, Y, R, B], [Y, Y, B, B], [Y, R, Y, Y], [R, R, Y, B], + [B, B, B, B], [R, B, B, B], [B, R, B, R], [B, B, R, R], [R, R, B, Y], [B, Y, B, Y], + [R, Y, Y, B], [R, B, B, Y], [Y, R, B, R], [R, Y, R, Y], [R, B, Y, B], [Y, B, B, R]] + +H = [[G, B, G], [B, Y, R], [B, R, B], [Y, G, Y], [R, G, B], [G, B, B], [R, B, G], [B, B, B], [R, R, R], [R, R, B], [G, R, R], [Y, R, R], [R, G, Y], [G, G, Y], [G, R, Y], [B, Y, G], [Y, R, Y], [G, G, R], [G, G, G], [B, Y, Y], [R, Y, B], [Y, B, G], [Y, Y, Y], [Y, B, B]] + +RT = [[B, B, Y], [Y, B, G], [G, R, B], [Y, G, Y], [R, G, G], [Y, G, B], [B, G, G], [R, B, Y], [R, R, G], [R, Y, G], [B, B, R], [Y, Y, Y]] + +LT = [[B, B, G], [R, Y, Y], [G, G, G], [G, Y, G], [G, R, B], [B, Y, Y], [B, B, B], [B, R, R], [Y, R, R], [R, R, R], [R, B, Y], [R, Y, G]] + +MASKS = [[0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 16, 17, 18, 19, 20, 21, 22, + 23], [0, 1, 2, 3, 4, 5, 6, 11, 12, 17, 18, 19, 20, 21, 22, 23], []] + +CARD_DIM = 200 + diff --git a/gentiles.py b/gentiles.py index cd08c0e..0cc31bd 100755 --- a/gentiles.py +++ b/gentiles.py @@ -13,7 +13,7 @@ # Boston, MA 02111-1307, USA. import os -from constants import C +from constants import C, H, RT, LT XCOR = ["-188.17646", "11.823541"] YCOR = ["162.71119", "362.71119"] @@ -82,6 +82,59 @@ def _svg_footer(): b = '</svg>\n' return a + b +def _svg_hex(top, left, right): + """ draw a hexagon """ + a = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + b = '<!-- Created with Python in Emacs -->\n' + c = '<svg\n' + d = ' xmlns:svg="http://www.w3.org/2000/svg"\n' + e = ' xmlns="http://www.w3.org/2000/svg"\n' + f = ' version="1.1"\n' + g = ' width="202.28767"\n' + h = ' height="231.94138"\n' + i = ' id="hexagon">\n' + j = ' <g transform="translate(-270.9034,-365.15558)">\n' + k = ' <path\n' + l = ' d="m 272.04724,423.15558 100.55096,-57.5 99.44904,57.5 -100.55096,57.5 -99.44904,-57.5 z"\n' + m = ' style="fill:' + top + ';fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + n = ' <path\n' + o = ' d="m 371.47534,596.59696 -100.07194,-58.32969 0.0719,-114.87539 100.07194,58.32969 -0.0719,114.87539 z"\n' + p = ' style="fill:' + left + '#0000ff;fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + q = ' <path\n' + r = ' d="m 372.61914,596.3201 100.07194,-58.32969 -0.0719,-114.87539 -100.07194,58.32969 0.0719,114.87539 z"\n' + s = ' style="fill:' + right + ';fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + t = ' </g>\n' + u = '</svg>\n' + return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q +\ + r + s + t + u + +def _svg_triangle(top, bottom, left, flip=False): + a = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + b = '<!-- Created with Python in Emacs -->\n' + c = '<svg\n' + d = ' xmlns:svg="http://www.w3.org/2000/svg"\n' + e = ' xmlns="http://www.w3.org/2000/svg"\n' + f = ' version="1.1"\n' + g = ' id="triange">\n' + if flip: + h = ' <g transform="matrix(-1,0,0,1,838.68554,-456.19895)">\n' + else: + h = ' <g transform="translate(-735.12125,-456.19895)">\n' + i = ' <g transform="translate(129.81785,111.40982)">\n' + j = ' <path\n' + k = ' d="m 607.82135,460.38159 98.22306,-54.95995 -65.57024,-0.92468 -32.65282,55.88463 z"\n' + l = ' style="fill:' + bottom + ';fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + m = ' <path\n' + n = ' d="m 607.3034,460.58514 0,-113.47935 33.29261,56.63592 -33.29261,56.84343 z"\n' + o = ' style="fill:' + left + ';fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />' + p = ' <path\n' + q = ' d="m 706.86769,405.18383 -98.70613,-58.3947 32.3358,57.2359 66.37033,1.1588 z"\n' + r = ' style="fill:' + top + ';fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + s = ' </g>\n' + t = '</g>\n' + u = '</svg>\n' + return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q +\ + r + s + t + u def open_file(datapath, filename): """ Create a file for writing """ @@ -101,6 +154,20 @@ def generator(datapath): f.write(svg) f.close() + for i, c in enumerate(H): + f = open_file(datapath, "hex-%d.svg" % (i)) + f.write(_svg_hex(c[0], c[1], c[2])) + f.close() + + for i, c in enumerate(RT): + f = open_file(datapath, "triangle-r-%d.svg" % (i)) + f.write(_svg_triangle(c[0], c[1], c[2])) + f.close() + + for i, c in enumerate(LT): + f = open_file(datapath, "triangle-l-%d.svg" % (i)) + f.write(_svg_triangle(c[0], c[1], c[2], flip=True)) + f.close() def main(): """ Command line version for testing """ |