import re
import copy
data = " \
M 5.32 6.32 \
L 8.45 10.78 \
C 10.3 10.5 12.65 12.35 15.11 15.79 \
L 20.45 20.78 \
Z "
offset_x = 5.32
offset_y = 6.32
def generateCode(cmd, data):
print("===============================================================")
for index,i in enumerate(data):
ss = "/* " + cmd[index] + " */ "
braced = True
for j in i:
if(braced):
ss = ss + "{" + str(j) + "f, "
braced = False
else:
ss = ss + str(j) + "f}, "
braced = True
print(ss)
print(cmd)
print("===============================================================")
def convert(s, offsetX, offsetY):
cmds = []
chars = ""
chars_list = []
started = False
for i in s:
if(i == '\n'):
continue
if(i == 'M' or i == 'L' or i == 'C' or i == 'Z'):
if(started):
chars_list.append(chars)
chars = ""
cmds.append(i)
started = True
continue
if(started):
chars += i
chars_list = [i.split() for i in chars_list]
for i in range(len(chars_list)):
for j in range(len(chars_list[i])):
if(j % 2 == 0):
chars_list[i][j] = round(float(chars_list[i][j])- offsetX, 4)
else:
chars_list[i][j] = round(float(chars_list[i][j]) - offsetY, 4)
generateCode(cmds, chars_list)
if __name__ == '__main__':
convert(data, offset_x, offset_y)
03-02
161