String[] cartLocation; int cartX; int cartY; int counter = 0; int avgY; int avgX; int sumX = 0; int sumY = 0; float totalX = 464; float totalY = 32; float fixedX = 320; float fixedY = 110; float locX; float locY; float perX; float perY; float hrzLnX; float hrzLnY; PFont font; PFont fontSmall; void setup() { size(640,480); background(15); noStroke(); smooth(); //font = loadFont("HelveticaNeue-Bold-48.vlw"); font = loadFont("HelveticaNeue-Light-20.vlw"); textFont(font); //textFont(fontSmall); cartLocation = loadStrings("cartMovement.txt"); int len = cartLocation.length; frameRate(10); loop(); } void draw() { fill(5); rectMode(CORNER); rect(0,0,width,height); //fill(5,5); //noStroke(); //rect(0,240 + 60, width, height/2 - 60); //fill(0,0,0,5); //rect(160,375,width,240); //rectMode(CENTER); // fill(255,0,100); stroke(175,175,175,65); rect (340-30,110,100,50); rect (340,110-30,100,50); quad (340, 110-30, 340+100, 110-30, 340+70, 110, 340-30, 110); quad (340, 110-30+50, 340+100, 110-30+50, 340+70, 110+50, 340-30, 110+50); //rect(340,110,100,100); noStroke(); if(counter < cartLocation.length) { String[] crd = split(cartLocation[counter], ','); cartX = Integer.parseInt(crd[0]); cartY = Integer.parseInt(crd[1]); //println(cartX + "," + cartY); locX = ((cartX + (.43 * counter)) - 275); locY = ((cartY + (.029493 * counter)) - 109); fill(60,20,190); //rect (locX,locY , 100,100); //rect (100,300,100,100); //center cube stroke(254,173,94); //stroke(255); noFill(); //fill (200,0,0); rectMode(CORNER); rect (locX-30,locY,100,50); rect (locX,locY-30,100,50); quad (locX, locY-30, locX+100, locY-30, locX+70, locY, locX-30, locY); quad (locX, locY-30+50, locX+100, locY-30+50, locX+70, locY+50, locX-30, locY+50); // quad (locX+30, locY-30, locX+130, locY-30, locX+100, locY, locX, locY); // quad (locX+30, locY-30+50, locX+130, locY-30+50, locX+100, locY+50, locX, locY+50); fill(254,173,94); stroke(254,173,94); text("FRAME " + counter + " OF " + cartLocation.length, 440,470); // calculate percent changes *********************** if (counter%50 == 0) { perX = abs(locX - fixedX) / totalX; perY = abs(locY - fixedY) / totalY; hrzLnX = locX-30; hrzLnY = locY+50; } fill(254,173,94); stroke(254,173,94); ///fill(153); text("horizontal: " + perX + " %",10,419); text("vertical: "+ perY + " %",10,443); text("[deviation agaist total distance travelled]", 10, 470); //rect(20,300,50,50); //println(perX + " / " + perY); stroke (255,0,0); fill(255,0,0); line(hrzLnX,hrzLnY-25,hrzLnX,hrzLnY+100); //vertical line line(hrzLnX + 30, hrzLnY, hrzLnX - 100, hrzLnY); // horizontal line //calculate total percentage of deviation from expected position in respect to the total distance the needle travelled. counter ++; } else { counter = 0; } }