xxxxxxxxxx
43
function setup() {
createCanvas(400, 400);
m=2
l=2.705
//https://en.wikipedia.org/wiki/Gravity_of_Earth
g1=9.78 //equator T1=3.304 s
g2=9.832 //pole T2=3.296 s
dt=0.02
t=0
theta1 = theta2 = 3.14/10; // Pendulum initial angle theta
omega1 = omega2= 0; // Initial angular velocity
C1 = 1; C2 = 3;}// Center points}
function draw() {
background(220);
t = t + dt;
// First pendulum
F1=-m*g1*sin(theta1)
epsilon1 = (F1/m)/l; //angular acceleration
omega1 = omega1 + epsilon1 * dt;
theta1 = theta1 + omega1 * dt;
xp1 = C1 - l * sin(theta1); // X coordinate of pendulum ball
yp1 = l * cos(theta1); // Y coordinate of pendulum ball
//draw it
ppm=100 //scale it to the canvas (from meters to pixels)
line(C1*ppm, 0, xp1*ppm, yp1*ppm);
ellipse(xp1*ppm, yp1*ppm, 20, 20);
// Second pendulum
F2=-m*g2*sin(theta2)
epsilon2 = (F2/m)/l; //angular acceleration
omega2 = omega2 + epsilon2 * dt;
theta2 = theta2 + omega2 * dt;
xp2 = C2 - l * sin(theta2); // X coordinate of pendulum ball
yp2 = l * cos(theta2); // Y coordinate of pendulum ball
//draw it
ppm=100 //scale it to the canvas (from meters to pixels)
line(C2*ppm, 0, xp2*ppm, yp2*ppm);
ellipse(xp2*ppm, yp2*ppm, 20, 20);
textSize(20); text("t = "+nf(t,0,2)+" s", 150,50);
}