xxxxxxxxxx
50
//Author:Pavel Kuriscak
function setup() {
createCanvas(400, 400);
ppm = 100; // Number of pixels per meter
th = 0.1; // Pendulum angle theta
v_th = 0; // Angular velocity
C = 2; // Center point
// Bogota set-up
L = 2.815; // http://groups.ist.utl.pt/wwwelab/wiki/index.php?title=World_Pendulum and
g = 9.776; // https://www.wolframalpha.com/widgets/view.jsp?id=e856809e0d522d3153e2e7e8ec263bf2
dt = 1/50;
t = 0; // Current time
num_swings = -0.25; //Number of swings
period = 0;
}
function draw() {
background(220);
old_th = th; //Remember theta before calculation
t = t + dt;
a_th = -g/L*th;
v_th = v_th + a_th*dt;
th = th + v_th*dt;
xp = C - L*sin(th); // X coordinate of pendulum ball
yp = L * cos(th); // Y coordinate of pendulum ball
scale(ppm);
strokeWeight(1/ppm);
line(C,0,xp,yp);
ellipse(xp,yp,0.2,0.2);
scale(1/ppm);
textSize(20);
text("t = "+nf(t,0,2), 50,50);
if (th*old_th < 0) {
num_swings = num_swings + 0.5;
period = t/num_swings;
}
text("N = "+nf(num_swings,0,2), 50, 75);
text("Period = "+nf(period,0,3), 50, 100);
}