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')
for x in range(0, x_count): for y in range(0, y_count): gen = get_neighbours([y, x], svg_pattern) neighbours = [] for n in gen: neighbours += [n] if svg_pattern[y][x] not in neighbours: mode = max(neighbours, key=neighbours.count) 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)