Animate a pendulum: Difference between revisions

→‎{{header|REXX}}: added the computer programming language REXX.
(→‎{{header|REXX}}: added the computer programming language REXX.)
Line 3,710:
 
SDL_Quit();</lang>
 
=={{header|REXX}}==
{{trans|ooRexx}}
<br>REXX doesn't have a portable graphics user interface (GUI), &nbsp; but
this version is similar to the '''Ada''' version and
just displays the coordinates of the end of the pendulum.
<lang rexx>/*REXX program displays the (x, y) coördinates (at the end of a swinging pendulum). */
parse arg cycles Plength theta . /*obtain optional argument from the CL.*/
if cycles=='' | cycles=="," then cycles= 100 /*Not specified? Then use the default.*/
if pLength=='' | pLength=="," then pLength= 10 /* " " " " " " */
if theta=='' | theta=="," then theta= 30 /* " " " " " " */
call time 'R' /*set the elapsed time (in seconds). */
speed= 0 /*velocity of the pendulum, now resting*/
d= digits() + 5 /*number of decimal digits to be shown.*/
g= -9.81 /*gravitation constant (for earth). */
do cycles; duration= time('E') /*swing the pendulum a number of times.*/
acceleration= g / pLength * sin(theta) /*compute the pendulum accelaration. */
x= sin(theta) * pLength /*calculate X coördinate of pendulum.*/
y= cos(theta) * pLength) /* " Y " " */
speed= speed + acceleration * duration /*calculate " speed " " */
theta= theta + speed * duration /* " " angle " " */
say 'x: ' right(x, d) " y: " right(y, d) /*display coördinates.*/
call delay 1/20 /*delay one-twentyth of a second. */
end /*cycles*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
pi: pi= 3.1415926535897932384626433832795028841971693993751058209749445923078; return pi
r2r: return arg(1) // (pi() * 2) /*normalize radians ──► a unit circle. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
cos: procedure; parse arg x; x=r2r(x); numeric fuzz min(6,digits()-3); z=1; _=1; x=x*x
p=z; do k=2 by 2; _=-_*x/(k*(k-1)); z=z+_; if z=p then leave; p=z; end; return z
/*──────────────────────────────────────────────────────────────────────────────────────*/
sin: procedure; parse arg x; x=r2r(x); _=x; numeric fuzz min(5, max(1,digits()-3)); q=x*x
z=x; do k=2 by 2 until p=z; p= z; _= -_*q/(k*k+k); z= z+_; end; return z</lang><br><br>
 
=={{header|Ring}}==