# -*- coding: utf-8 -*- #Copyright (c) 2009, Walter Bender #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal #in the Software without restriction, including without limitation the rights #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #copies of the Software, and to permit persons to whom the Software is #furnished to do so, subject to the following conditions: #The above copyright notice and this permission notice shall be included in #all copies or substantial portions of the Software. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #THE SOFTWARE. import os from gettext import gettext as _ RED_STROKE = "#FF6040" RED_FILL = "#FFC4B8" BLUE_STROKE = "#0060C8" BLUE_FILL = "#ACC8E4" GREEN_STROKE = "#00B418" GREEN_FILL = "#AFE8A8" PURPLE_STROKE = "#780078" PURPLE_FILL = "#E4AAE4" color_pairs = ([RED_STROKE,RED_FILL], [GREEN_STROKE,GREEN_FILL], [BLUE_STROKE,BLUE_FILL], [PURPLE_STROKE,PURPLE_FILL]) fill_styles = ("none","gradient","solid") card_types = ("X","O","C") def background(f,stroke,fill,width): f.write("\n") def header(f,stroke,fill,width): f.write("\n") f.write("\n") f.write("\n") background(f,stroke,fill,width) f.write("\n") def footer(f): f.write("\n") f.write("\n") def circle(f, x, style, stroke, fill): f.write("\n") elif style == "gradient": f.write(" style=\"fill:" + fill + ";stroke:" + stroke + \ ";stroke-width:1.8;\" />\n") else: f.write(" style=\"fill:" + stroke + ";stroke:" + stroke + \ ";stroke-width:1.8;\" />\n") f.write("\n") def check(f, x, style, stroke, fill): f.write("\n") elif style == "gradient": f.write(" style=\"fill:" + fill + ";stroke:" + stroke + \ ";stroke-width:1.8;\" />\n") else: f.write(" style=\"fill:" + stroke + ";stroke:" + stroke + \ ";stroke-width:1.8;\" />\n") def cross(f, x, style, stroke, fill): f.write("\n") elif style == "gradient": f.write(" style=\"fill:" + fill + ";stroke:" + stroke + \ ";stroke-width:1.8;\" />\n") else: f.write(" style=\"fill:" + stroke + ";stroke:" + stroke + \ ";stroke-width:1.8;\" />\n") def check_card(f, n, style, stroke, fill): if n == 1: check(f, 45.5, style, stroke, fill) elif n == 2: check(f, 25.5, style, stroke, fill) check(f, 65.5, style, stroke, fill) else: check(f, 5.5, style, stroke, fill) check(f, 45.5, style, stroke, fill) check(f, 85.5, style, stroke, fill) def cross_card(f, n, style, stroke, fill): if n == 1: cross(f, 45.5, style, stroke, fill) elif n == 2: cross(f, 25.5, style, stroke, fill) cross(f, 65.5, style, stroke, fill) else: cross(f, 5.5, style, stroke, fill) cross(f, 45.5, style, stroke, fill) cross(f, 85.5, style, stroke, fill) def circle_card(f, n, style, stroke, fill): if n == 1: circle(f, 45.5, style, stroke, fill) elif n == 2: circle(f, 25.5, style, stroke, fill) circle(f, 65.5, style, stroke, fill) else: circle(f, 5.5, style, stroke, fill) circle(f, 45.5, style, stroke, fill) circle(f, 85.5, style, stroke, fill) def number(f, x, string, stroke): f.write(" \n") f.write(" "+string+"\n") f.write(" ") def number_card(f, t, n, stroke): number(f, 63.5, str(n), stroke) def word(f, x, string, stroke): f.write(" \n") f.write(" "+string+"\n") f.write(" ") def word_card(f, s, string, stroke): word(f, 63.5, string[s], stroke) def open_file(datapath, filename): return file(os.path.join(datapath, filename), "w") def close_file(f): f.close() def generator(datapath): # pattern cards i = 0 for t in card_types: for c in color_pairs: for n in range(1,4): for s in fill_styles: filename = "pattern-%d.svg" % (i) f = open_file(datapath, filename) header(f,"#000000",c[1],"0.5") if t == "O": circle_card(f,n,s,c[0],c[1]) elif t == "C": check_card(f,n,s,c[0],c[1]) else: cross_card(f,n,s,c[0],c[1]) footer(f) close_file(f) i += 1 # number cards i = 0 for t in card_types: # ignoring this field for c in color_pairs: for n in range(1,4): for s in [5,7,11]: filename = "number-%d.svg" % (i) f = open_file(datapath, filename) header(f,"#000000",c[1],"0.5") number_card(f,t,n*s,c[0]) footer(f) close_file(f) i += 1 # word cards i = 0 for t in card_types: # ignoring this field for c in color_pairs: for n in range(0,3): for s in range(0,3): filename = "word-%d.svg" % (i) f = open_file(datapath, filename) header(f,"#000000",c[1],"0.5") if n == 0: word_card(f,s,[_("dog"),_("cat"),_("mouse")],c[0]) elif n == 1: word_card(f,s,[_("apple"),_("bread"),_("cheese")],c[0]) else: word_card(f,s,[_("sun"),_("moon"),_("earth")],c[0]) footer(f) close_file(f) i += 1 f = open_file(datapath, "match.svg") header(f,"#A0A0A0","#F0F0F0","3.0") footer(f) close_file(f) f = open_file(datapath, "selected.svg") header(f,"#000000","none","3.0") footer(f) close_file(f) def main(): 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()