Example #1
0
 def create_svg_code(self, array, filename, format_string, version):
     svg = SVG()
     cell_size = 20
     svg_size = cell_size * (len(array) + 8)
     svg.prep_for_drawing(svg_size, svg_size)
     length = (4 * version) + 17
     # Bottom right format information
     br = [[x, 8] for x in range(length - 1, length - 9, -1)]
     br += [[8, y] for y in range(length - 7, length, 1)]
     for i in range(len(br)):
         x = br[i][0]
         y = br[i][1]
         if(format_string[i] == '1'):
             svg.add_coloured_rect(x*20, y*20, 'rgb(0, 0, 0);')
     # Top left format information.
     tl = [[8, y] for y in range(0,9)]
     tl += [[x, 8] for x in range(7,-1,-1)]
     c = 0
     for i in range(len(tl)):
         x = tl[i][0]
         y = tl[i][1]
         if not ((x == 6 and y == 8) or (x == 8 and y == 6)):
             if(format_string[c] == '1'):
                 svg.add_coloured_rect(x*20, y*20, 'rgb(0, 0, 0);')
             c+=1
     for x in range(len(array)):
         for y in range(len(array[x])):
             if(array[x][y]) == 1:
                 svg.add_rect(x*20, y*20)
     svg.save(filename + '.svg')
Example #2
0
                svg_pattern[y][x] = mode

# 8

svg_cell_size = 10
width = x_count * svg_cell_size
height = y_count * svg_cell_size
col_sym.prep_for_drawing(width, height)
col_sym.mid_arrows(svg_cell_size, width, height)
blw_nsy.prep_for_drawing(width, height)
blw_nsy.mid_arrows(svg_cell_size, width, height)
col_nsy.prep_for_drawing(width, height)
x = y = svg_cell_size  # to allow drawing of midpoint arrows
for row in svg_pattern:
    for colour_index in row:
        col_sym.add_rect(svg_palette, colour_index, x, y, svg_cell_size)
        blw_nsy.add_rect(svg_palette, colour_index, x, y, svg_cell_size)
        col_nsy.add_rect(svg_palette, colour_index, x, y, svg_cell_size)
        x += svg_cell_size
    y += svg_cell_size
    x = svg_cell_size
blw_nsy.major_gridlines(svg_cell_size, width, height)
col_sym.major_gridlines(svg_cell_size, width, height)

# 9

size = 40
key.prep_for_drawing(size * 13, size * len(svg_palette))
x = y = 0
for i in range(len(svg_palette)):
    key.add_key_colour(x, y, size, i, svg_palette[i])