We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm doing a little text to load in some points from an xml file and loading them into an arrayList to display them on screen as ellipses. I've got some code now but when I run it I only get one ellipse drawn at 0,0 even though that isn't one of the points that I'm trying to load in.
Here is my code with my class Points
class Points {
float xPos, yPos;
Points(float _xPos, float _yPos) {
xPos = _xPos;
yPos = _yPos;
}
}
XML xml;
ArrayList<Points> point = new ArrayList<Points>();
void setup() {
size(640, 360);
background(255);
//point = new Points(-10, -10);
//loadData();
xml = loadXML("newPointList.xml");
XML[] children = xml.getChildren("points");
//point = new Points[children.length];
for (int i = 0; i < children.length; i ++) {
XML xVal = children[i].getChild("x");
float x = xVal.getInt ("x");
XML yVal = children[i].getChild("y");
float y = xVal.getInt ("y");
Points addingData = new Points(x, y);
println("x " + x + ", " + "y " + y);
point.add(addingData);
}
}
void draw() {
for (int i = 0; i< point.size(); i++) {
Points drawPoints = point.get(i);
ellipse(drawPoints.xPos, drawPoints.yPos, 10, 10);
}
}
Here is the basic XML of points I'm trying to use called newPointList.xml
<?xml version="1.0"?>
<pointList>
<points>
<x>30</x>
<y>20</y>
</points>
<points>
<x>85</x>
<y>20</y>
</points>
<points>
<x>85</x>
<y>75</y>
</points>
</pointList>
Feel like the process is right, but still only has a point as zero. Any help would be appreciated. Thanks
Answers
Removed by SiriusCG.
nice.
Thanks for your response GoToLoop. Nice implementation.
I wanted to use an ArrayList so I could remove elements from the array at a later stage. I've tried to implement this previously and with your code but I'm not sure how to create an arrayList of type XML and PVector[] and then use that in a similar way to load in the points into the arrayList.
Be grateful to know how that would be done.
Thanks
https://Processing.org/reference/ArrayList.html
Thanks for this. Makes sense.