int col = color(255); boolean Arrows = false; int Y_AXIS = 1; int X_AXIS = 2; color b1, b2; float angle; //forces between 20N and 100 N? //distance between 40cm and 200cm ArrayList arrAL = new ArrayList(); Arrow arrow1; Arrow arrow2; Arrow arrow3; Arrow arrow4; Arrow [] arrOb = new Arrow [4]; void setup() { window.Processing.data.val1 = true; //up window.Processing.data.val2 = false; //down window.Processing.data.val3 = true; //up window.Processing.data.val4 = false; //down window.Processing.data.force1 = 60; window.Processing.data.force2 = 80; window.Processing.data.force3 = 30; window.Processing.data.force4 = 100; window.Processing.data.dist1 = 140; window.Processing.data.dist2 = 110; window.Processing.data.dist3 = 90; window.Processing.data.dist4 = 160; window.Processing.data.totalT = -119; size(620,410); //if this is changed, also have to change translation b1 = color(76,117,117); b2 = color(100,171,222); rectMode(CENTER); smooth(4); } void draw() { background(200,226,250); /*"with translate you "displace objects within the display window", which also applies to whatever gets drawn by controlP5, as all controlP5 elements are drawn at the end of the draw method. to get around this you could use pushMatrix() and popMatrix() to encapsulate your translations, e.g."*/ pushMatrix(); arrow1 = new Arrow("1",color(69,25,179), window.Processing.data.dist1, 0, window.Processing.data.force1, false, window.Processing.data.val1); arrow2 = new Arrow("2",color(135,179,25), window.Processing.data.dist2, 0, window.Processing.data.force2, false, window.Processing.data.val2); arrow3 = new Arrow("3",color(179,25,58), window.Processing.data.dist3, 0, window.Processing.data.force3, true, window.Processing.data.val3); arrow4 = new Arrow("4",color(25,179,146), window.Processing.data.dist4, 0, window.Processing.data.force4, true, window.Processing.data.val4); translate(width/2, (height-190)); rotateMe(); noStroke(); rect(0,22, 26, 65); setGradient(-13,-10, 26/2, 65, b1, b2, X_AXIS); setGradient(0,-10, 26/2, 65, b2, b1, X_AXIS); fill(150,102,101); ellipse(0, 0, 10, 10); fill(204,148,147); ellipse(0, 0, 6, 6); popMatrix(); } void rotateMe(){ pushMatrix(); int one = round(window.Processing.data.force1*window.Processing.data.dist1)*arrow1.torqueSign/100; int two = round(window.Processing.data.force2*window.Processing.data.dist2)*arrow2.torqueSign/100; int three = round(window.Processing.data.force3*window.Processing.data.dist3)*arrow3.torqueSign/100; int four = round(window.Processing.data.force4*window.Processing.data.dist4)*arrow4.torqueSign/100; int check = one + two + three + four; /* if (check != 0) { if (check < 0 && angle<23) { angle=angle+1; } if (check > 0 && angle>-23) { angle=angle-1; } } if(check==0){ if(angle<0){ angle=angle+1; } if(angle>0){ angle=angle-1; } } */ if (window.Processing.data.totalT != 0) { if (window.Processing.data.totalT < 0 && angle<23) { angle=angle+1; } if (window.Processing.data.totalT > 0 && angle>-23) { angle=angle-1; } } if(window.Processing.data.totalT==0){ if(angle<0){ angle=angle+1; } if(angle>0){ angle=angle-1; } } rotate(radians(angle)); fill(74,108,138); stroke(88); strokeWeight(1.7); rect(0,0, 400, 7,10,10,0,0); stroke(255,0,0); strokeWeight(.5); line(-200,-110,200,-110); line(-175,-120,-175,-100); line(-70,-115,-70,-105); line(175,-120,175,-100); line(70,-115,70,-105); line(-200,-120,-200,-100); line(-195,-115,-195,-105); line(-190,-115,-190,-105); line(-185,-115,-185,-105); line(-180,-115,-180,-105); line(-170,-115,-170,-105); line(-165,-115,-165,-105); line(-160,-115,-160,-105); line(-155,-115,-155,-105); line(-150,-120,-150,-100); line(-145,-115,-145,-105); line(-140,-115,-140,-105); line(-135,-115,-135,-105); line(-130,-115,-130,-105); line(-125,-120,-125,-100); line(-120,-115,-120,-105); line(-115,-115,-115,-105); line(-110,-115,-110,-105); line(-105,-115,-105,-105); line(-100,-120,-100,-100); line(-95,-115,-95,-105); line(-90,-115,-90,-105); line(-85,-115,-85,-105); line(-80,-115,-80,-105); line(-75,-120,-75,-100); line(-65,-115,-65,-105); line(-60,-115,-60,-105); line(-55,-115,-55,-105); line(-50,-120,-50,-100); line(0,-120,0,-100); line(200,-120,200,-100); line(195,-115,195,-105); line(190,-115,190,-105); line(185,-115,185,-105); line(180,-115,180,-105); line(170,-115,170,-105); line(165,-115,165,-105); line(160,-115,160,-105); line(155,-115,155,-105); line(150,-120,150,-100); line(145,-115,145,-105); line(140,-115,140,-105); line(135,-115,135,-105); line(130,-115,130,-105); line(125,-120,125,-100); line(120,-115,120,-105); line(115,-115,115,-105); line(110,-115,110,-105); line(105,-115,105,-105); line(100,-120,100,-100); line(95,-115,95,-105); line(90,-115,90,-105); line(85,-115,85,-105); line(80,-115,80,-105); line(75,-120,75,-100); line(65,-115,65,-105); line(60,-115,60,-105); line(55,-115,55,-105); line(50,-120,50,-100); textSize(10); fill(0, 102, 153); text("200", -210, -127); text("150", -160, -127); text("100", -110, -127); text("50", -57, -127); text("200", 190, -127); text("150", 140, -127); text("100", 90, -127); text("50", 43, -127); text("0", -4, -127); text("cm", 7, -100); strokeWeight(1); fill(150,102,101); ellipse(0, 0, 10, 10); fill(204,148,147); ellipse(0, 0, 6, 6); placeArrows(); popMatrix(); } void placeArrows(){ arrOb[0] = arrow1; arrOb[1] = arrow2; arrOb[2] = arrow3; arrOb[3] = arrow4; arrAL.add(arrow1); arrAL.add(arrow2); arrAL.add(arrow3); arrAL.add(arrow4); Arrows = true; float [] arr = new float [4]; arr[0] = arrow1.force; arr[1] = arrow2.force; arr[2] = arrow3.force; arr[3] = arrow4.force; float [] arr2 = sort(arr); /*for (int i=3;i>-1;i--){ for(int j=0;j<4;j++){ if(arr2[i]==arrOb[j].force){ pushMatrix(); translate(arrOb[j].xpos,arrOb[j].ypos); rotate(-radians(angle)); arrOb[j].xpos=0; arrOb[j].ypos=0; arrOb[j].display(); popMatrix(); } } } */ for (int i=3;i>-1;i--){ for(int j=0;j=(window.Processing.data.dist1-15) && (window.Processing.data.force1==window.Processing.data.force2 || window.Processing.data.force2=(window.Processing.data.dist1-15) && window.Processing.data.dist2<=window.Processing.data.dist1 && this.up==arrow1.up && window.Processing.data.force1>(.45*fk*window.Processing.data.force2)){ text(this.name, x-7+xOffset*fk+2, y-3*sign*dim1*fk-3+sign*yOffset);}else if(this.name=="2" && window.Processing.data.dist2<=(window.Processing.data.dist1+15) && window.Processing.data.dist2>window.Processing.data.dist1 && this.up==arrow1.up && window.Processing.data.force1>(.45*fk*window.Processing.data.force2)){ text(this.name, x-7-xOffset*fk, y-3*sign*dim1*fk-3+sign*yOffset);}else if(this.name=="2" && (window.Processing.data.dist2<(window.Processing.data.dist1-15) || window.Processing.data.dist2>(window.Processing.data.dist1+15)) && this.up==arrow1.up){ text(this.name, x-7+1, y-3*sign*dim1*fk-3+yOffset2-2);}else{text(this.name, x-7+1, y-3*sign*dim1*fk-3+yOffset2-2);}; } void numbPlace2(int xOffset, int yOffset, int yOffset2, int sign){ float fk = log(force*.15)/log(9); int dim1 = 22; int dim2 = 10; int x=xpos; int y=ypos; if(name=="4" && this.up==arrow3.up && window.Processing.data.dist4<=(window.Processing.data.dist3+15) && window.Processing.data.dist4>=(window.Processing.data.dist3-15) && (window.Processing.data.force3==window.Processing.data.force4 || window.Processing.data.force4=(window.Processing.data.dist3-15) && window.Processing.data.dist4<=window.Processing.data.dist3 && this.up==arrow3.up && window.Processing.data.force3>(.45*fk*window.Processing.data.force4)){ text(this.name, x-7-xOffset*fk-1, y-3*sign*dim1*fk-3+sign*yOffset);}else if(this.name=="4" && window.Processing.data.dist4<=(window.Processing.data.dist3+15) && window.Processing.data.dist4>window.Processing.data.dist3 && this.up==arrow3.up && window.Processing.data.force3>(.45*fk*window.Processing.data.force4)){ text(this.name, x-7+xOffset*fk+1, y-3*sign*dim1*fk-3+sign*yOffset);}else if(this.name=="4" && (window.Processing.data.dist4<(window.Processing.data.dist3-15) || window.Processing.data.dist4>(window.Processing.data.dist3+15)) && this.up==arrow3.up){ text(this.name, x-7+1, y-3*sign*dim1*fk-3+yOffset2-2);}else{text(this.name, x-7+1, y-3*sign*dim1*fk-3+yOffset2-2);}; } }