You are here

An Animation of Distillation-Part IIm, The Stirrer


Brian J Pankuch
Department of Chemistry, Union County College
Cranford, NJ 07016

Note: This article was scanned using OCR from the Fall 1989 CCCE Newsletter. Please contact us if you identify any OCR errors.
This is the second of a series of articles which describe how to program an animated graphic for distillation. The complete graphic shows a flickering flame, a rotating stirrer bar, falling liquid, and a slowly increasing liquid distillate. In Part I the production of the flame was described. In this part, we explore the illusion of a spinning bar. It is assumed that you have a copy of CHEMUTIL 2(1) available for your Apple II series microcomputer.
A BASIC listing of a program which shows a spinning bar is given on page 20 of the CHEMUTIL-2 documentation. It works by printing a series of images of the bar. It uses the same principle that was used to simulate the flame but with a significant difference in application. The flame printed characters directly over one another, and it did not matter in which order they were chosen. The bar uses two characters printed side by side and the order is important.
to show a half tum of the bar requires the definition of ten new characters. These are then printed in pairs rapidly. The pain are shown in Figure 1. A full turn of the bar requires rapid printing in place of each pair in the order ABC DE DC B A. A continuing loop like that gives the illusion of a rotating stirrer bar. The CHEMUTIL-2 program is not quite as sophisticated as this in that it actually
loops through ABC DE A. You can see that if you add a delay to that program so that each image stays on the screen for a longer time(2). The result of that economy of code is that the bar has a small hitch in its rotation which actually helps that rotating magnetic bars often have a small kick in an otherwise smooth movement.
We need to rewrite the routine so that it can be successfully integrated with the flame routine and the yet-to-be developed falling drop code. The same logistical problema must be solved as were encountered with the flame. An appropriate program loop would be:-
Locate bar position : Print bar pair(A): Delay : Locate bar position : Print bar pair(B) : Delay : etc. However, we must arrange to have the full nine pair sequence for a full tum rather than the truncated five pair sequence of the CHEMUTIL-2 example. The reason is that we cannot be sure that the bar will rotate fast enough so that the hitch is acceptable when the flame and falling drop animation are integrated into it. We can rotate the bar slower and maintain the illusion when the nine pair sequence is in place. One way to code this would be to have two loops. The first loop prints images A to E and the second from D to B. However execution time can be reduced by defining six more characters which are duplicates of pairs D, C and B respectively. Then successive full sweeps through the eight pairs of characters will constitute a series of full turns of the stirrer bar. The additional six characters lowing the ten characters already available
in CHEMUTIL-2 starting at $7390. 
Listing 1 will add the duplicated characters to CHEMUTIL-2 and Listing 2 1s the BASIC code for the rotating bar. Notice the similarity of Listing 2 to the program used to show the flickering flame. The ability to stop the animation by pressing the S-key has been included.
Listing 1
10 FOR I = 1 to 48
20 Read X : POKE (29599 + I)){
40 DATA 0, 0, 0, 120, 124, 126, 124, 120
60 DATA 0, 0, 0, 15, 31, 63 1 31, 15
60DATAO,O,O, 112,120,126,120,112
70 DATA 0, 0, 0, 7, 15, 31, 15, 7,
80 DATA 0, 0, 0, 96, 112, 120, 112,96,
90 DATA 0, 0, 0, 3, 7, 15, 7, 3,
Listing 2
20 FOR I = 106 TO 121 STEP 2
30 VTAB 10 : HTAB 10
40 PRINT CHR$ (I) + CHR$ (I + 1)
60 X= PEEK <-16368), 0 : IF X= 211 THEN I = 122 : GOTO 80
70GOTO 20
80 VTAB 20 : END
The source of the code is given for the machine language version. Enter it into your Apple with an assembler as via the monitor. Then, after BWADing CHEMUTIL-2 and running Listing 1,
RUN 10 CALL 25042
        20 CALL 31760
        30 IF PEEK (31746) = 16 THEN END
        40 GOTO 20
Notice that the resulting stirrer is very jerky. That is because the delay, at Line 71 of the source code, is too short so that several bar images are drawn while the monitor screenis being refreshed. Try poking other values at 31861 ($7C75) and seeing the effect on the bar.
The machine language version was written so that the program terminates when the.S-key is pressed or after 256 bar images have been shown. The latter is controlled by the TOTSPN counter.
In effect can be negated by removing Line 54 of the source code or by poking 31832,234:31833,234 and 31834,234. It is useful when your overall program requires that the animation cease when the S-key is pressed or after a set time by a loop like FOR I = 1 TO 200 :CALL 31760: NEXT I.
The next part of this series will discuss how the two separate routines for stirrer and flame can be integrated s? that they appear to be executing srmultaneously.Only machine language source code will be given since BASIC coding would execute too slowly for a realistic illusion.


10/05/89 to 10/09/89