class Limb { int numSegments = 2; float[] x = new float[numSegments]; float[] y = new float[numSegments]; float[] angle = new float[numSegments]; float[] len = { 50.0, 75.0 }; // float len[a]=150; float targetX, targetY; Limb() { } void setlen(float lenA, float lenB) { len[0]=lenA; len[1]=lenB; } void anchor(float anchorX, float anchorY) { x[numSegments-1]=anchorX; y[numSegments-1]=anchorY; } void positionSegment(int a, int b) { x[b] = x[a] + cos(angle[a]) * len[a]; y[b] = y[a] + sin(angle[a]) * len[a]; } void reachSegment(int i, float xin, float yin) { float dx = xin - x[i]; float dy = yin - y[i]; angle[i] = atan2(dy, dx); targetX = xin - cos(angle[i]) * len[i]; targetY = yin - sin(angle[i]) * len[i]; } void segment(int i, float sw) { strokeWeight(sw); pushMatrix(); translate(x[i], y[i]); rotate(angle[i]); line(0, 0, len[i], 0); popMatrix(); } float getX(int i) { return x[i]; } float getY(int i) { return y[i]; } float getAngle(int i) { return angle[i]; } float getLength(int i) { return len[i]; } void update(float xTarget, float yTarget) { reachSegment(0, xTarget, yTarget); //makes first segment follow the ball for (int i=1; i=1; i--) { positionSegment(i, i-1); // puts each segment in relative place } // THIS one places/draws the segments with X and Y for (int i=0; i