The green flag loads TrotBot and launches the balls you need to block. Press left arrow to walk left, right arrow to walk right, "z" to jump left, "x" to jump right. For a description of how the algorithms are used in the code see https://www.diywalkers.com/linkage-simulation.html We used this code to optimize TrotBot's linkage. Here's a video of a LEGO TrotBot walking around: www.youtube.com/watch?v=U2Mxs6YZJWM
Mechanical linkages connect "bars" (TrotBot's blue lines) at "joints" that allow the bars to rotate. When the arrow keys are pressed, TrotBot's crank turns, which moves all the joints to make it walk. This code uses algebra and analytical geometry to calculate each joint's X and Y position, allowing TrotBot to be drawn with the pen. The joint positions depend on the bar's lengths, which are loaded into the bar variables when the green flag is pressed. To see a map of TrotBot's bar lengths press "2", for the joint map press "1". To make the code run faster, the X,Y values of each joint are first calculated for one full rotation of the crank, which are saved to each joint's list. Then, when TrotBot is moved the "rotation" variable is incremented and the joint values are retrieved from these lists. The main algorithm used to find the joint's X,Y values is called "Circle Intersection", which finds the two points where 2 circles intersect. There are 4 choices for choosing between the two points: "low Y", "high Y", "left X", and "right X". If you look at the joint you are trying to calculate and imagine the path it should take, that should help you to see which of the 4 choices will always give you the correct intersection point. An overview of mechanical walkers like TrotBot can be found here: www.diywalkers.com/walker-abcs "Circle Intersection" is based on Paul Bourke's "Intersection of two circles" solution, where he used the Pythagorean theorem and some clever analytical geometry to find the 2 intersection points. His derivation is the 5th one down on this webpage: http://paulbourke.net/geometry/circlesphere/