<meta charset="utf-8" />
<script src="http://spelprogrammering.nu/simple.js">
function start()
{
g = 9.82;
l = 2.5;
m = 1;
theta0 = pi/4;
theta = 0;
phi = pi/2;
omega = sqrt(g/l);
SMax = m*g*(3*cos(0)-2*cos(theta0));
vMax = sqrt(2*g*l*(cos(0)-cos(theta0)));
T = 2*pi*sqrt(l/g);
t = 0;
updatesPerSecond = 50;
}
function update()
{
clearScreen();
S = m*g*(3*cos(theta)-2*cos(theta0));
v = sqrt(2*g*l*(cos(theta)-cos(theta0)));
theta = theta0*sin(omega*t + phi);
math.polarLine(0, 0, theta + 3*pi/2, l, mixColor(floor(255*S/SMax), 0, 0));
math.polarPoint(theta + 3*pi/2, l, 20, "black");
t += 1/updatesPerSecond;
math.text(-2.7, 2.5, 12, "Snörets längd: " + floor(l*100)/100+"m");
math.text(-2.7, 2, 12, "Pendelns massa: " + floor(m*100)/100+"kg");
math.text(-2.7, 1.5, 12, "Startvinkel: " + floor(theta0*100)/100+" radianer");
math.text(-2.7, 1, 12, "Snöret utsätts för maximalt: "+floor(SMax*100)/100+"N");
math.text(-2.7, 0.5, 12, "Pendelns maximala hastighet: "+floor(vMax*100)/100+"m/s");
math.text(-2.7, 0, 12, "Period: "+floor(T*100)/100+"s");
math.text(0, 2.5, 12, "Nuvarande tid: " + floor(t*100)/100+"s");
math.text(0, 2, 12, "Nuvarande vinkel: "+floor(theta*100)/100+" radianer");
math.text(0, 1.5, 12, "Nuvarande kraft i snöret: "+floor(S*100)/100+"N");
math.text(0, 1, 12, "Pendelns hastighet: "+floor(v*100)/100+"m/s");
}
</script>
Gå tillbaka