#!/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 General Public
# License along with this library; if not, write to the
# Free Software Foundation, 51 Franklin Street, Suite 500 Boston, MA
# 02110-1335 USA
import os
from constants import C, H, RT
XCOR = ["-188.17646", "11.823541"]
YCOR = ["162.71119", "362.71119"]
def _svg_header():
""" the common header every card shares """
a = '\n'
b = '\n'
c = '\n'
return a + b
def _svg_lower_right(color):
""" draw an arc in the upper right quadrant """
a = _svg_circle(XCOR[0], YCOR[1])
b = ' style="fill:' + color + ';fill-opacity:1;fill-rule:nonzero;stroke:none" />\n'
return a + b
def _svg_upper_left(color):
""" draw an arc in the upper right quadrant """
a = _svg_circle(XCOR[1], YCOR[0])
b = ' style="fill:' + color + ';fill-opacity:1;fill-rule:nonzero;stroke:none" />\n'
return a + b
def _svg_lower_left(color):
""" draw an arc in the upper right quadrant """
a = _svg_circle(XCOR[1], YCOR[1])
b = ' style="fill:' + color + ';fill-opacity:1;fill-rule:nonzero;stroke:none" />\n'
return a + b
def _svg_footer():
""" A common footer """
a = ' \n'
b = '\n'
return a + b
def _svg_hex(top, left, right, rotate=0):
""" draw a hexagon """
a = '\n'
b = '\n'
c = '\n'
n = ' \n'
q = ' \n'
t = ' \n'
u = '\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, rotate=None):
a = '\n'
b = '\n'
c = '\n'
m = ' \n'
p = ' \n'
s = ' \n'
t = '\n'
u = '\n'
return a + b + c + d + e + f + g + rr1 + h + i + j + k + l + m + n + o + \
p + q + r + s + t + rr2 + u
def open_file(datapath, filename):
""" Create a file for writing """
return file(os.path.join(datapath, filename), "w")
def generator(datapath):
""" Make the cards: squares with circles, hexagons, and triangles """
for i, c in enumerate(C):
f = open_file(datapath, "card-%d.svg" % (i))
svg = _svg_header()
svg += _svg_upper_left(c[0])
svg += _svg_lower_left(c[1])
svg += _svg_lower_right(c[2])
svg += _svg_upper_right(c[3])
svg += _svg_footer()
f.write(svg)
f.close()
for i, c in enumerate(H):
f = open_file(datapath, "hexagon-r0-%d.svg" % (i))
f.write(_svg_hex(c[0], c[1], c[2]))
f.close()
f = open_file(datapath, "hexagon-r120-%d.svg" % (i))
f.write(_svg_hex(c[0], c[1], c[2], 120))
f.close()
f = open_file(datapath, "hexagon-r240-%d.svg" % (i))
f.write(_svg_hex(c[0], c[1], c[2], 240))
f.close()
for i, c in enumerate(RT):
f = open_file(datapath, "triangle-r0-%d.svg" % (i))
f.write(_svg_triangle(c[0], c[1], c[2]))
f.close()
f = open_file(datapath, "triangle-r60-%d.svg" % (i))
f.write(_svg_triangle(c[0], c[1], c[2], rotate=60))
f.close()
f = open_file(datapath, "triangle-r120-%d.svg" % (i))
f.write(_svg_triangle(c[0], c[1], c[2], rotate=120))
f.close()
f = open_file(datapath, "triangle-r180-%d.svg" % (i))
f.write(_svg_triangle(c[0], c[1], c[2], rotate=180))
f.close()
f = open_file(datapath, "triangle-r240-%d.svg" % (i))
f.write(_svg_triangle(c[0], c[1], c[2], rotate=240))
f.close()
f = open_file(datapath, "triangle-r300-%d.svg" % (i))
f.write(_svg_triangle(c[0], c[1], c[2], rotate=300))
f.close()
def main():
""" Command line version for testing """
return 0
if __name__ == "__main__":
if not os.path.exists(os.path.join(os.path.abspath('.'), 'images')):
os.mkdir(os.path.join(os.path.abspath('.'), 'images'))
generator(os.path.join(os.path.abspath('.'), 'images'))
main()