How to make a smooth animation

Using the HIDDEN draw mode, an original graphics mode of Decimal BASIC, enables graphics commands can be performed without refreshing the screen until escape of this mode. In doing so, smooth animations can be obtained.
To be more precise, we make a program as follows.

100 OPTION ARITHMETIC NATIVE 
110 DEF f(x)=x^2 + (a-4)*x + (a^2-3*a +1)
120 SET WINDOW -3,6,-5,5
130 FOR a=-3 TO 4 STEP 0.01
140    SET DRAW MODE Hidden              ! transfer to the hidden draw mode
150    CLEAR                             ! initialize the screen           
160    DRAW axes
170    SET LINE COLOR 1
180    FOR x=-3 TO 6 STEP 0.01
190       PLOT LINES: x,f(x);
200    NEXT x
210    PLOT LINES
220    SET LINE COLOR 3
230    FOR t=-3 TO a STEP 0.01
240       PLOT LINES: -(t-4)/2, (3*t^2-4*t-12)/4;
250    NEXT t
260    PLOT POINTS:  -(a-4)/2, (3*a^2-4*a-12)/4
270    SET DRAW MODE explicit            ! return to the explicit draw mode 
280    WAIT DELAY 0.01                   ! control the speed
290 NEXT a
300 END


We use MAT PLOT statements to decease wasteful calculation repetitions. In the following example, the coordinates that was calculated the last time remains in the array "vertex".

100 OPTION ARITHMETIC NATIVE 
110 OPTION BASE 0
120 DIM vertex(700,1)
130 DEF f(x)=x^2 + (a-4)*x + (a^2-3*a +1)
140 SET POINT COLOR 4
150 SET WINDOW -3,6,-5,5
160 FOR a=-3 TO 4 STEP 0.01
170    SET DRAW MODE Hidden  
180    CLEAR                               
190    DRAW axes
200    LET u=-(a-4)/2
210    LET v=(3*a^2-4*a-12)/4
220    SET LINE COLOR 3
230    LET L=ROUND((a+3)*100)
240    LET vertex(L,0)=u
250    LET vertex(L,1)=v
260    MAT PLOT LINES, LIMIT L+1 : vertex
270    SET LINE COLOR 1
280    FOR x=-3 TO 6 STEP 0.01
290       PLOT LINES: x,f(x);
300    NEXT x
310    PLOT LINES
320    PLOT POINTS: u,v 
330    SET DRAW MODE explicit   
340 NEXT a
350 END


We can also use the NOTXOR mode to speed up the drawing.
In the NOTXOR mode, graphics to be drawn on the white background are drawn in the designated color, but when graphics are to be drawn on the other color background, they are drawn in a particular color that is determined by the designated color and the existng background color, which is the color in which graphics are drawn twice, they should vanish.

100 OPTION ARITHMETIC NATIVE
110 DEF f(x)=x^2 + (a-4)*x + (a^2-3*a +1)
120 SUB DrawCurve
130    SET DRAW MODE hidden
140    FOR x=-3 TO 6 STEP 0.1
150       PLOT LINES: x,f(x);
160    NEXT x
170    PLOT LINES
180    SET DRAW MODE explicit
190 END SUB
200 SET WINDOW -3,6,-5,5
210 SET POINT COLOR "RED" 
220 DRAW axes
230 FOR a=-3 TO 4 STEP 0.1
240    SET DRAW MODE NOTXOR    
250    CALL DrawCurve
260    WAIT DELAY 0.05       ! wait for 0.05 seconds
270    CALL DrawCurve        ! vanish the curves by twice drawing
280    SET DRAW MODE OVERWRITE  ! exit the NOTXOR draw mode
290    PLOT POINTS:  -(a-4)/2, (3*a^2-4*a-12)/4
300 NEXT a
310 END



Back