adnil
YaBB Newbies
Offline
Posts: 28
int[] adds 0's from one method to the next
Apr 8th , 2009, 9:20am
I am trying to write application that splits up user input text and creates a visualisation from it. I have allocated x,y coordinates to certain parameters that appear in words. According to the user input i am collecting these coordinates in an arraylist, then put them into an int[] and from there draw shapes at the specific positions. This works fine. I then want to link the shapes with lines. This doesn't work. Suddenly the program draws more lines than its supposed to, and seems to get 0 values from somewhere. I have put the code below. can anybody help? void drawInCorrectPosition(String[] two, String[] twoGrams, String[] lines, color[] c1, color[] c2, float[] r, float[] g, float[] b, int[] car1, int[] car2) { ArrayList thatXPos = new ArrayList(); //new arraylist to store all the x values and then when drawing run throught these x values for (int i= 0; i < twoGrams.length; i++) // compare user input with preset list { for (int j = 0; j < two.length; j++) { if(twoGrams[i].equals(two[j]) == true) { int xpos = leftmargin + ( i * 3); thatXPos.add(new Integer(xpos)); int[] xPosCount = new int[thatXPos.size()]; for (int k = 0 ; k < thatXPos.size(); k++) { xPosCount[k] = ((Integer)thatXPos.get(k)).intValue(); int y = height - 200; noStroke(); fill((c1[j]+c2[j])/ 2); rect (xpos,y, 30, 40); //put a rectangle for every stored number in the int[] callLines(y, two, twoGrams, xPosCount, xpos); } } } } } void callLines(int y, String[] two, String[] twoGrams, int[] xPosCount, int xpos) { for (int i = 0; i < xPosCount.length-1; i++) //connect the rectangle with u-shaped line { int lineStartX = (xPosCount[i]+30)+i*4; int lineEndX = xPosCount[i+1]+30; stroke(100); noFill(); beginShape(); vertex(lineStartX, y+40); vertex(lineStartX, y+51); vertex(lineEndX, y+51); vertex(lineEndX, y+40); endShape(); } }