XML Data
in
Programming Questions
•
1 year ago
Hello, I am fairly new to processing and am being taught XML with processing. My teacher provided us with some code and I have some ideas what I'd like to do with it, however I am not sure how to go about it. For my data I chose to go with species of endangered animals and their numbers left. What I would like to do is bring that data into processing by a XML document, and I would like the data to be connected to images for each specie. I only chose 10 animals, so it shouldn't be too difficult to work with. What I would like to do with this is in the initial window to show just a row of icons I have that represents each animal. When the mouse is pressed on the icon, the current stage would be replaced with a new stage that shows information on the animal, and even a better picture of said animal. Is this too difficult for me to do, is there a simple way to do this?
Minus all the PImages, this is the code my teacher gave us to work with. Also, I've changed around some of the variable names, but not all of them.
Thanks for any help received.
Nicole
PFont font;
PImage ferret;
PImage owl;
PImage seal;
PImage falcon;
PImage pronghorn;
PImage quita;
PImage plover;
PImage wolvie;
XMLElement xml;
float pSpecie;
String pName;
float minHeight;
float maxHeight;
float xloc;
float yloc;
float xlocOffset;
void setup() {
size(800, 300);
xml = new XMLElement(this, "bullHeight.xml");//change to whatever I name
int numPlayers = xml.getChildCount();
float[] heightArray = new float[numPlayers];
String[] nameArray = new String[numPlayers];
rectMode(CENTER);
font = loadFont("SansSerif-12.vlw");
textFont(font);
textAlign(CENTER);
for(int i=0; i < numPlayers; i++) {
XMLElement player = xml.getChild(i);
pName = player.getContent();
nameArray[i] = pName;
pSpecie = player.getFloatAttribute("pSpecie");//change this to whatever I name
heightArray[i] = pSpecie;
minHeight = min(heightArray);
maxHeight = max(heightArray);
}
xlocOffset = width/numPlayers; //
xloc = -xlocOffset/2; // initial location -44
for(int i=0; i < heightArray.length; i++) {
float h = map(heightArray[i], minHeight, maxHeight, height*.5, height*.8);
rect(xloc += xlocOffset, height-h/2, 30, h); // 800 minus half of h which lines up at bottom
text(nameArray[i], xloc, height-h-10);
}
}
1