Animate a pendulum: Difference between revisions

Content added Content deleted
(Applesoft BASIC)
Line 340: Line 340:


=={{header|BASIC}}==
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{trans|Commodore BASIC}}
Two shapes are used to draw and undraw the pendulum. Undrawing and drawing is done on the page that is not being displayed to make the animation flicker free. Animation code is compacted and hoisted to the beginning of the program. Variables are defined for all non-zero values.
<lang gwbasic> 0 ON NOT T GOTO 9: FOR Q = 0 TO T STEP 0:BX = PX + L * S * SIN (F):BY = PY - L * S * COS (F): HCOLOR= 0: FOR I = 0 TO N(P): DRAW T + (I = N(P)) AT X(P,I),Y(P,I): NEXT I:N(P) = 0: HCOLOR= C
1 FOR X = PX TO BX STEP (BX - PX) / Z:Y = PY + (X - PX) * (BY - PY) / (BX - PX): DRAW T AT X,Y:X(P,N(P)) = X:Y(P,N(P)) = Y:N(P) = N(P) + 1: NEXT X
2 HCOLOR= T: DRAW B AT BX,BY:X(P,N(P)) = BX:Y(P,N(P)) = BY:A = PEEK (R + P):P = NOT P: POKE U,W + W * P:A = G * SIN (F) / L / H:V = V + A / Z:F = F + V: NEXT Q
9 DIM N(1),X(1,11),Y(1,11): FOR P = 32 TO 64 STEP 32: POKE 230,P: HCOLOR= 0: HPLOT 0,0: CALL 62454: NEXT :R = 49236:P = ( PEEK (R) + PEEK (49234) + PEEK (49239) + PEEK (49232)) * 0 + 1
10 S$ = CHR$ (2) + CHR$ (0) + CHR$ (6) + CHR$ (0) + CHR$ (8) + CHR$ (0) + "-" + CHR$ (0) + ".%'?>..%" + CHR$ (0): PRINT MID$ ( STR$ ( FRE (0)) + S$,1,0);: POKE 236, PEEK (131): POKE 237, PEEK (132)
15 S = PEEK (236) + PEEK (237) * 256: POKE 232, PEEK (S + 1): POKE 233, PEEK (S + 2): SCALE= 1: ROT= 0
20 T = 1
25 F = 3.1415926535 / 2: REM THETA
30 G = 9.81
35 L = 0.5
40 V = 0: REM SPEED
45 PX = 140
50 PY = 80
55 S = 20
60 Z = 10
65 C = 3
70 B = 2
75 U = 230
80 W = 32
85 H = 50
90 GOTO</lang>
==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}