You are here

An Animation of Distillation Part III Combined Heating and Stirring


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.
The two earlier parts of this series showed how to write routines for displaying a flickering flame and a spinning stirrer bar on the Apple graphics screen using CHEMUTIL-2 (1) as the character generator. In this article, I shall describe how the routine can be combined so that the flame and stirrer appear to be activated simultaneously. Since a BASIC program would execute too slowly for effective animation only the machine language source code is given.
The overall algorithm is simple in principle.Show flame (1), show stirrer (1), delay, show flame (2), show stirrer (2), delay, etc. As we have previously indicated, the delay is present because it will allow us to control the overall speed of the illusion and also leaves room for the introduction of the falling drop routine later.
This algorithm would work but is too limited because the bar would rotate at the same speed as the flame flickered. the simple alternation of flame and stirrer means that whatever affects the speed of one affects tihe speed of the other. A rapidly flickering flame with a slow stirrer would be impossible. Fortunately, we have already allowed for the latter poasibili ty when we wrote the separate routines because they have separate delay routines incorporated into each. More importantly, we included the counter TOTCNT and TOTSPN which allow an exit from either routine when the counters are zeroed by the executing programs. this is the true significance of Line 48 and. Line 54 in the FLAME and SPINNER source codes.
The improved algorithm becomes:
(A) Show a series of flame images with a delay between them until the TOTCNT counter becomes zero then ?
(B) Show a series of stirrer images with a delay between them until the TOTSPN counter becomes zero then
(C) Loop back to (A).
The flame delay and the stirrer delay need not be the same length and one (or both) of them can be used to check the keyboard periodically. There are now four locations which can be used to adjust the speed of the overall animation or the flame and stirrer separately. They correspond to the lengths of the two delay loops and the initial values chosen for TOTCNT and TOTSPN.
The source code for the combined routines shows how simple it? was to combine them. Since the separate routines wee debugged separately, we can be certain that if the combination does not function the interface is at fault. In my experience the most likely errors at this point are made by not initializing variables and counters as the switch is made from one working routine to the other.
To execute the code it must be entered at $7C10 and CHEMUTIL-2 BLOADed. Listing 1 from part II must have been run to supply the extra stirrer images. Then the following brief BASIC
program is run:
        10 CALL 25042 : PRINT"&"
        20 CALL 31760 C
You will now see a flickering flame with a rotating bar over it. The bar has been placed over the flame by Lines 33-36 of the source code. You can easily alter its relative position if you desire but this program puts it over the flame because it is the correct relative position for a distillation which is our ultimate goal.
In this code as written there are 32 flame images between every stirrer image. i.e. There are 256 flame images for every full tum of the stirrer bar. It is instructive to see the effects of introducing other values fro,n 1-255 into TOTSPN, TOTCNT and the two delay intervals. Try poking values into locations 31850 (TOTSPN), 131855 (TOTCNT), 31891 (DELAY) and 31963 (DELSPN).
An advantage to writing the separate routines and then interfacing them is that they can still be used separately when needed. The equivalent combination in BASIC is a loop like GOSUB !FLAME : GOSUB STIRRER. A loo.p like this will show only the flame if the first line of the stirrer routine is RETURN. So by poking the first byte of the SPINST routine in the machine language code with the equivalent of RETURN only the flame image will appear. Try Poke 31913,96 and see the result.
The disadvantage of interfacing separate routines in this way is that the combination will execute slower than a specially designed combination program. This is seldom of real consequence for machine language because the length of the delay loops can be adjusted to compensate, but in BASIC programs it can be devastating. Rememberthat when you do animation in machine language you usually must deliberately slow it down but in BASIC the animation will be too slow from the first.
The fourth part of this series will discuss the falling drop and accumulating liquid animation.
(1) Bendall, V. "CHEMUTIL-2,AChemistry Programming Utility"; Project SERAPinM,NSF Science Education; Department of Chemistry, Eastern Michigan University, Ypsilanti, MI 48197, 1985.
(2) For example, add the following line to the CHEMUTIL-2listing. 75 FORK = 1 to 100 : NEXT K and RUN the program again .


10/10/89 to 10/14/89