Functional Objects

Function
Two pendulums swing independently in xy plane and are connected with arms to a pen which draws on a bed which on a pendulum which is also free to swing in both x and y directions. Kinematics are based on simple harmonic motion with exponential damping.
Based on the simulation by Andy Giger
pendulum 1 by kit :
Randomly set the parameter values

Path Step size Scale Max Cycles Line Width Line Color Padding

Function code

```            function fn(t,p,scale) {
//  3 pendulums A=1,B=2,C=3
//  x amplitude,y amplitude, phase x, phase y, frequency f, damping
//  input  px, px, degrees, degrees, cycles/second, s?

var a1x =Ax;
var a1y =Ay;
var p1x =APx;
var p1y =APy;
var f1  =AF;
var td1 =AD;

var a2x =Bx;
var a2y =By;
var p2x =BPx;
var p2y =BPy;
var f2  =BF;
var td2 =BD;

var a3x =Cx;
var a3y =Cy;
var p3x =CPx;
var p3y =CPy;
var f3  =CF;
var td3 =CD;

//  pendulums arranged in right-angled triangle base R

var R = 100.0;

var Ax = 0.0, Ay = R;   // central position of A pendulum
var Bx = R, By = 0.0;   // central position of B pendulum

//pendulum position
//  x1,y1 Pendulum A  relative to centre
//  x2,y2 Pendulum B  relative to centre
//  x3,y3 Pendulum C  relative to centre

// x,y damped sinusoidal positions
// same damping on all pendulums
var d1 = td1==0 ? 1 : Math.exp(-t /360 / td1) ;
var x1 = a1x * d1 * sin(f1 * t + p1x);
var y1 = a1y * d1 * sin(f1 * t + p1y);

var d2 =  d1;   // Math.exp(-t /360 / td2) ;
var x2 = a2x * d2 * sin(f2 * t + p2x);
var y2 = a2y * d2 * sin(f2 * t + p2y);

var d3 = d1;    // Math.exp(-t /360 / td3)
var x3 = a3x * d3 * sin(f3 * t + p3x);
var y3 = a3y * d3 * sin(f3 * t + p3y);

// Cx,Cy position of Pendulum A relative to origin
var Cx = x1 + Ax;  var Cy = y1 + Ay;
// Dx,Dy position of Pendulum B relative to origin
var Dx = x2 + Bx ; var Dy = y2 + By;
// D relative to C
var DCx = Cx - Dx; var DCy = Cy - Dy;
// distance CD
var CD = Math.sqrt(Math.pow(DCx,2) + Math.pow(DCy,2));

// P is at the end of two links C-P, and D-P each of length L
var L=R;

// angle between C and P
var gamma = r2d(Math.acos( CD / (2 * L) ) + Math.acos( DCy / CD )) ;

var Px = Cx - L * sin(gamma) ;
var Py = Cy - L * cos(gamma);

// point relative to pendulum C  ie on the paper surface relative to its centre
var x = Px - x3;
var y = Py - y3;

if (log==1)
if (t % 36 == 0)
console.log(t,x1,y1,x2,y2,x3,y3,Px,Py,x,y,d1,gamma);
return [scale*x, scale*y];
}
```