I have a XML file like this:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<path d="M 50 50 L 50 90 L 90 90 z" fill="red"/>
<path d="M 160 170 L 160 130 L 120 130 z" fill="green"/>
<path d="M 200 30 L 180 30 L 180 50 L 220 50 z" fill="blue"/>
<path d="M 40 100 L 40 140 L 60 140 L 60 120 z" fill="yellow"/>
<path d="M 210 70 L 230 90 L 270 90 L 270 50 L 230 50 z" fill="purple"/>
<path d="M 180 130 L 180 170 L 220 210 L 240 190 z" fill="olive"/>
<path d="M 100 200 L 120 180 L 80 140 L 80 180 z" fill="magenta"/>
</svg>
These are the cordinates of the shapes that I have to work with.What I'm trying to do is the get ALL the cordinates of these shapes and store them seperately.In order to make math calculations.Like getting x1=50 x2=50 x3=90 y1=50 y2=90 y3=90 for the first one(red)
How can I compile these lines and store cordinates?
EDIT:I solved it and wanted to share with people. This code gets the values and colours for X and Y cordinates of the shapes and stores them in the list. Thanks for the suggestions below:
import xml.etree.ElementTree as ET
import re
r = re.compile('[0-9]{1,}')
root = ET.parse('pieces_A.xml').getroot()
line=[]
y=[]
X=[]
Y=[]
newlist=[]
c=[]
i=0
#gets the numbers and colours.
for child in root:
line.append((child.attrib['d']))
c.append(child.attrib)
y.append((r.findall(line[i])))
i +=1
#appends the colours and x,y cordinates to a new list
for i in range(len(y)):
for j in range(len(y[i])):
if j%2==0:
X.append(y[i][j])
if j%2==1:
Y.append(y[i][j])
newlist.append([ X,Y,c[i]['fill'] ] )
X=[]
Y=[]
print(newlist)
So right now what is does is this for every item first 3 points are x cordinates and second points are for the y cordinates and the last element is the colour of the shape:
[[['50', '50', '90'], ['50', '90', '90'], 'red'],