langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
36
Task/Animate-a-pendulum/XPL0/animate-a-pendulum.xpl0
Normal file
36
Task/Animate-a-pendulum/XPL0/animate-a-pendulum.xpl0
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
|
||||
proc Ball(X0, Y0, R, C); \Draw a filled circle
|
||||
int X0, Y0, R, C; \center coordinates, radius, color
|
||||
int X, Y;
|
||||
for Y:= -R to R do
|
||||
for X:= -R to R do
|
||||
if X*X + Y*Y <= R*R then Point(X+X0, Y+Y0, C);
|
||||
|
||||
|
||||
def L = 2.0, \pendulum arm length (meters)
|
||||
G = 9.81, \acceleration due to gravity (meters/second^2)
|
||||
Pi = 3.14,
|
||||
DT = 1.0/72.0; \delta time = screen refresh rate (seconds)
|
||||
def X0=640/2, Y0=480/2; \anchor point = center coordinate
|
||||
real S, V, A, T; \arc length, velocity, acceleration, theta angle
|
||||
int X, Y; \ball coordinates
|
||||
|
||||
[SetVid($101); \set 640x480x8 graphic display mode
|
||||
T:= Pi*0.75; V:= 0.0; \starting angle and velocity
|
||||
S:= T*L;
|
||||
repeat A:= -G*Sin(T);
|
||||
V:= V + A*DT;
|
||||
S:= S + V*DT;
|
||||
T:= S/L;
|
||||
X:= X0 + fix(L*100.0*Sin(T)); \100 scales to fit screen
|
||||
Y:= Y0 + fix(L*100.0*Cos(T));
|
||||
Move(X0, Y0); Line(X, Y, 7); \draw pendulum
|
||||
Ball(X, Y, 10, $E\yellow\);
|
||||
while port($3DA) & $08 do []; \wait for vertical retrace to go away
|
||||
repeat until port($3DA) & $08; \wait for vertical retrace signal
|
||||
Move(X0, Y0); Line(X, Y, 0); \erase pendulum
|
||||
Ball(X, Y, 10, 0\black\);
|
||||
until KeyHit; \keystroke terminates program
|
||||
SetVid(3); \restore normal text screen
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue