First segment Key code:
1 var New P2. Linearspring (Holderbody, Circlebody, {2 Localanchora: [0, 0],3 Localanchorb: [0, 0],4 stiffness:100,5 damping:1, 6 restlength:1.57}); 8 world.addspring (S1);
: Here Localanchora, the concept of localanchorb is still relative to the coordinates within the respective object, and when [0,0], represents the center point of the object. By default, this coordinate is the center of the object. This coordinates indicate where one end of the spring is hooked on the object. The stiffness represents the strength of the spring. By default, it is 100. Look at the effect of the stiffness:1000, and then pull the ball, you will find the ball back and forth quickly, that means the strength of the spring is higher. Damping, which is the resistance of the spring. By default, it is 1. When the spring is stretched, the resistance of the spring to the contraction action is controlled by this property. Restlength, literally understood, is the natural stretching length when the spring relaxes. The default is the current distance between the world anchor points, which is the length of the distance between the two anchor points. Practice Source Address: https://gist.github.com/yxzblue/3a66babfb93b889f0833#file-linearspring-html p2.js v0.6.0 Package, Link:/http Pan.baidu.com/s/1mgsw7xa Password: Bj85p2.js's github address: https://github.com/schteppe/p2.js
P2. JS Linear Spring (linearspring) Memo