class Limb { int numSegments = 2; float[] x = new float[numSegments]; float[] y = new float[numSegments]; float[] angle = new float[numSegments]; float segLength=50; float targetX, targetY; Limb() { } 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]) * segLength; y[b] = y[a] + sin(angle[a]) * segLength; } 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]) * segLength; targetY = yin - sin(angle[i]) * segLength; } void segment(float x, float y, float a, float sw) { strokeWeight(sw); pushMatrix(); translate(x, y); rotate(a); line(0, 0, segLength, 0); popMatrix(); } 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