Exemple #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')
# a

if (len(sys.argv) < 3):
    print(
        "function requires an input filename, number of colours, stitch count and mode"
    )
    sys.exit(0)

input_file_name = sys.argv[1]  # input file name, has to be a jpg
num_colours = int(sys.argv[2])  # number of colours to use in the pattern
count = int(sys.argv[3])  # stitch count, number of stitches in x axis

# black_white, minor, symbols

col_sym = SVG(False, True, True)
blw_nsy = SVG(True, True, True)
col_nsy = SVG(False, False, False)
key = SVG(False, True, True)

# b

im = Image.open(input_file_name)

# c

new_width = 1000
pixelSize = int(new_width / int(count))
new_height = int(new_width * im.size[1] / im.size[0])
im = im.resize((new_width, new_height), Image.NEAREST)
from SVG import SVG
from Raster import Rasterizer
from CoordinateTrace import CoordinateTrace
from MotorStep import MotorStep

if __name__ == "__main__":

    svg = SVG(200, 30)
    rasterizer = Rasterizer()

    while True:

        file = input('Input file: ')
        input_type = file.split('.')[1]

        if input_type not in ['svg', 'jpg', 'ct']:
            print('Error: Invalid input type.')
            continue

        output = input('Export as (.ct/.mstp): ')
        output_name = output.split('.')[0]
        output_type = output.split('.')[1]

        if output_type not in ['ct', 'mstp']:
            print('Error: Invalid output type.')
            continue

        if '/' in output_name:
            print('Error: Name cannot contain paths.')
            continue