Home » CEEFAX disks » telesoftware9.adl » 26-09-88/GRAVTXT
26-09-88/GRAVTXT
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » CEEFAX disks » telesoftware9.adl |
Filename: | 26-09-88/GRAVTXT |
Read OK: | ✔ |
File size: | 162B bytes |
Load address: | 0000 |
Exec address: | FFFFFFFF |
Duplicates
There is 1 duplicate copy of this file in the archive:
- CEEFAX disks » telesoftware5.adl » 30-01-88/GRAVTXT
- CEEFAX disks » telesoftware9.adl » 26-09-88/GRAVTXT
File contents
ANIMATION TECHNIQUES WITH GRAVITY When writing a game, or any program in which movement of graphics sprites is incorporated, it is often desirable to make certain characters move with a realism that we experience in life. Gravity is one of these realities, and when incorporated in a program the effects can be quite interesting (or startling when they go wrong!). Gravity is a force which acts on all bodies that have mass, but because a sprite has no mass (it's being held in computer memory) we have to introduce an artificial gravity into the animation. The introduction of gravity has many applications which include the movement of a bouncing ball, the slowing down and then speeding up of a sprite when it jumps up and then down in a game, or the realistic swing of a rope in games like HUNCHBACK. When applied in a horizontal plane the methods descibed can also be used to simulate, for example, snooker balls on a table that has friction. PROJECTILE MOVEMENT Program 1 is a general purpose ball throwing program (!). Various parameters can be changed so that there effects upon the balls movement can be seen by altering 9 different values. These parameters are altered by entering the corresponding number and then, if a number is required the user is prompted to enter a value, otherwise if the option is of a YES/NO type, the value will toggle. The default values are such that the ball will be thrown up in the 'air' and then return to ground. The after image of the ball can be turned off using option 8, as can the line references. A few points may be noted : 1. The X velocity and the Y velocity are TOTALLY independant of each other. 2. The X velocity remains constant throughout the motion because there is no acceleration (gravity) acting in the X plane. 3. The initial Y velocity will, in general, be large to start with, reduce as the ball gets higher until it stops, and then it will begin to gain speed as it falls back down to the ground. 4. By altering the X velocity it may be seen that the range of the ball is increased because the ball can travel further to the right before it returns to the ground. The best way to understand what is going on is to simply play with the program. HOW GRAVITY IS SIMULATED The movement of the ball uses simple animation techniques, and the introduction of gravity is achieved on line 370. The variable 'yvel%' holds a value that represents the Y velocity of the ball i.e. it is the number of pixils which are jumped during subsequent plotting of the ball. Thus initially 'yvel%' is large so that the ball appears to move fast, but this value is slowly decreased by subtracting a value held in 'gravity' so that the ball appears to slow down as it gets higher. Eventually 'yvel%' will become zero, afterwhich it will become negative (i.e. a -ve velocity), so the ball will slowly begin to move in the opposite direction and then gather speed. The variable 'gravity' represents the rate of change of the Y velocity (its acceleration, or 'the gravitational field strength'). CIRCULAR MOTION AND GRAVITY - the pendulum When bodies move under the influence of gravity and are also effected by an external force it becomes more difficult to simulate their motion on a computer, but the secret is to take each force in turn and program the effects that these forces will have on the body one at a time. For example, a true pendulum bob moves in a circlular arc and is effected by gravity, resulting in oscillations of the pendulum. This can be simulated on a computer by firstly making a ball move in a circle on the screen and then, as seen in program 1, it is simply a matter of altering the velocity of the bob at different stages of its motion. Program 2 simulates true pendulum motion. It was written by firstly obtaining a circle function (using two SINE waves 90 degrees out of phase - don't worry about this), and then making a graphic character move in this circle. Having achieved this, the initial position of the bob is decided and then the pendulum is allowed to rotate in a circular path initially moving downwards. The procedure 'xy' calculates the x-y position of the bob at any angle (held in 'pos') of the circle. Thus, to obtain circuler motion it is simply a matter of giving 'pos' consecutive values from 0 to 360 dgrees and plotting each x-y corrdinate for the corresponding value of 'pos'. However, we want the pendulum to start from a horizontal position, so the initial value of 'pos' is set to 90 degrees (line 240). The speed of the bob is determined by the step rate of the angle through which the bob turns (i.e. the rate of change of 'pos'). This step rate is held in the variable 'vel' so if, for example, 'vel' = 10, then the bob would move in a circle in jumps of 10 degrees. It is now a simple matter to introduce gravity (as we did in program 1 ) by increasing the velocity of the bob as it falls. This is achieved on line 360. There is, however, one problem. Because the velocity is constantly increasing from a positive value as it swings downwards, it will never reach a turning point at which the velocity will begin to get slower, so the result will be a constantly accelerating bob moving in a circle. Thus we must put in a condition whereby once the bob reaches a certain velocity, the sign of the gravity is changed resulting in the bob slowing down until it eventually stops at the top of its swing (see lines 340,350). Alternatively, the sign of 'gravity' could be swapped when the value of 'pos' equaled 180 degrees, but you have to make sure that 'pos' does actually become exactly 180 degrees at some point of the swing. ROB ANDERSON. SEPTEMBER 1986
00000000 0d 41 4e 49 4d 41 54 49 4f 4e 20 54 45 43 48 4e |.ANIMATION TECHN| 00000010 49 51 55 45 53 20 57 49 54 48 20 47 52 41 56 49 |IQUES WITH GRAVI| 00000020 54 59 0d 0d 0d 57 68 65 6e 20 77 72 69 74 69 6e |TY...When writin| 00000030 67 20 61 20 67 61 6d 65 2c 20 6f 72 20 61 6e 79 |g a game, or any| 00000040 20 70 72 6f 67 72 61 6d 20 69 6e 20 77 68 69 63 | program in whic| 00000050 68 20 6d 6f 76 65 6d 65 6e 74 20 6f 66 20 67 72 |h movement of gr| 00000060 61 70 68 69 63 73 20 73 70 72 69 74 65 73 0d 69 |aphics sprites.i| 00000070 73 20 69 6e 63 6f 72 70 6f 72 61 74 65 64 2c 20 |s incorporated, | 00000080 69 74 20 69 73 20 6f 66 74 65 6e 20 64 65 73 69 |it is often desi| 00000090 72 61 62 6c 65 20 74 6f 20 6d 61 6b 65 20 20 63 |rable to make c| 000000a0 65 72 74 61 69 6e 20 63 68 61 72 61 63 74 65 72 |ertain character| 000000b0 73 20 6d 6f 76 65 0d 77 69 74 68 20 61 20 72 65 |s move.with a re| 000000c0 61 6c 69 73 6d 20 74 68 61 74 20 77 65 20 65 78 |alism that we ex| 000000d0 70 65 72 69 65 6e 63 65 20 69 6e 20 6c 69 66 65 |perience in life| 000000e0 2e 20 47 72 61 76 69 74 79 20 69 73 20 6f 6e 65 |. Gravity is one| 000000f0 20 6f 66 20 74 68 65 73 65 0d 72 65 61 6c 69 74 | of these.realit| 00000100 69 65 73 2c 20 61 6e 64 20 77 68 65 6e 20 69 6e |ies, and when in| 00000110 63 6f 72 70 6f 72 61 74 65 64 20 69 6e 20 61 20 |corporated in a | 00000120 70 72 6f 67 72 61 6d 20 74 68 65 20 65 66 66 65 |program the effe| 00000130 63 74 73 20 63 61 6e 20 62 65 20 71 75 69 74 65 |cts can be quite| 00000140 0d 69 6e 74 65 72 65 73 74 69 6e 67 20 28 6f 72 |.interesting (or| 00000150 20 73 74 61 72 74 6c 69 6e 67 20 77 68 65 6e 20 | startling when | 00000160 74 68 65 79 20 20 67 6f 20 77 72 6f 6e 67 21 29 |they go wrong!)| 00000170 2e 0d 0d 47 72 61 76 69 74 79 20 69 73 20 61 20 |...Gravity is a | 00000180 66 6f 72 63 65 20 77 68 69 63 68 20 61 63 74 73 |force which acts| 00000190 20 6f 6e 20 61 6c 6c 20 62 6f 64 69 65 73 20 74 | on all bodies t| 000001a0 68 61 74 20 68 61 76 65 20 6d 61 73 73 2c 20 62 |hat have mass, b| 000001b0 75 74 20 62 65 63 61 75 73 65 20 61 0d 73 70 72 |ut because a.spr| 000001c0 69 74 65 20 68 61 73 20 6e 6f 20 6d 61 73 73 20 |ite has no mass | 000001d0 28 69 74 27 73 20 62 65 69 6e 67 20 68 65 6c 64 |(it's being held| 000001e0 20 69 6e 20 63 6f 6d 70 75 74 65 72 20 6d 65 6d | in computer mem| 000001f0 6f 72 79 29 20 77 65 20 68 61 76 65 20 74 6f 0d |ory) we have to.| 00000200 69 6e 74 72 6f 64 75 63 65 20 61 6e 20 61 72 74 |introduce an art| 00000210 69 66 69 63 69 61 6c 20 67 72 61 76 69 74 79 20 |ificial gravity | 00000220 69 6e 74 6f 20 74 68 65 20 61 6e 69 6d 61 74 69 |into the animati| 00000230 6f 6e 2e 20 54 68 65 20 69 6e 74 72 6f 64 75 63 |on. The introduc| 00000240 74 69 6f 6e 20 6f 66 0d 67 72 61 76 69 74 79 20 |tion of.gravity | 00000250 68 61 73 20 6d 61 6e 79 20 61 70 70 6c 69 63 61 |has many applica| 00000260 74 69 6f 6e 73 20 77 68 69 63 68 20 69 6e 63 6c |tions which incl| 00000270 75 64 65 20 74 68 65 20 6d 6f 76 65 6d 65 6e 74 |ude the movement| 00000280 20 6f 66 20 61 20 62 6f 75 6e 63 69 6e 67 0d 62 | of a bouncing.b| 00000290 61 6c 6c 2c 20 74 68 65 20 73 6c 6f 77 69 6e 67 |all, the slowing| 000002a0 20 64 6f 77 6e 20 61 6e 64 20 74 68 65 6e 20 73 | down and then s| 000002b0 70 65 65 64 69 6e 67 20 75 70 20 6f 66 20 61 20 |peeding up of a | 000002c0 73 70 72 69 74 65 20 77 68 65 6e 20 69 74 20 6a |sprite when it j| 000002d0 75 6d 70 73 20 75 70 0d 61 6e 64 20 74 68 65 6e |umps up.and then| 000002e0 20 64 6f 77 6e 20 69 6e 20 61 20 67 61 6d 65 2c | down in a game,| 000002f0 20 6f 72 20 74 68 65 20 72 65 61 6c 69 73 74 69 | or the realisti| 00000300 63 20 73 77 69 6e 67 20 6f 66 20 61 20 72 6f 70 |c swing of a rop| 00000310 65 20 69 6e 20 67 61 6d 65 73 20 6c 69 6b 65 0d |e in games like.| 00000320 48 55 4e 43 48 42 41 43 4b 2e 20 57 68 65 6e 20 |HUNCHBACK. When | 00000330 61 70 70 6c 69 65 64 20 69 6e 20 61 20 68 6f 72 |applied in a hor| 00000340 69 7a 6f 6e 74 61 6c 20 70 6c 61 6e 65 20 74 68 |izontal plane th| 00000350 65 20 6d 65 74 68 6f 64 73 20 64 65 73 63 69 62 |e methods descib| 00000360 65 64 20 63 61 6e 0d 61 6c 73 6f 20 62 65 20 75 |ed can.also be u| 00000370 73 65 64 20 74 6f 20 73 69 6d 75 6c 61 74 65 2c |sed to simulate,| 00000380 20 66 6f 72 20 65 78 61 6d 70 6c 65 2c 20 73 6e | for example, sn| 00000390 6f 6f 6b 65 72 20 62 61 6c 6c 73 20 6f 6e 20 61 |ooker balls on a| 000003a0 20 74 61 62 6c 65 20 74 68 61 74 20 68 61 73 0d | table that has.| 000003b0 66 72 69 63 74 69 6f 6e 2e 0d 0d 50 52 4f 4a 45 |friction...PROJE| 000003c0 43 54 49 4c 45 20 4d 4f 56 45 4d 45 4e 54 0d 0d |CTILE MOVEMENT..| 000003d0 50 72 6f 67 72 61 6d 20 31 20 69 73 20 61 20 67 |Program 1 is a g| 000003e0 65 6e 65 72 61 6c 20 70 75 72 70 6f 73 65 20 62 |eneral purpose b| 000003f0 61 6c 6c 20 74 68 72 6f 77 69 6e 67 20 70 72 6f |all throwing pro| 00000400 67 72 61 6d 20 28 21 29 2e 20 56 61 72 69 6f 75 |gram (!). Variou| 00000410 73 0d 70 61 72 61 6d 65 74 65 72 73 20 63 61 6e |s.parameters can| 00000420 20 62 65 20 63 68 61 6e 67 65 64 20 73 6f 20 74 | be changed so t| 00000430 68 61 74 20 74 68 65 72 65 20 65 66 66 65 63 74 |hat there effect| 00000440 73 20 75 70 6f 6e 20 74 68 65 20 62 61 6c 6c 73 |s upon the balls| 00000450 20 6d 6f 76 65 6d 65 6e 74 0d 63 61 6e 20 62 65 | movement.can be| 00000460 20 73 65 65 6e 20 62 79 20 61 6c 74 65 72 69 6e | seen by alterin| 00000470 67 20 39 20 64 69 66 66 65 72 65 6e 74 20 76 61 |g 9 different va| 00000480 6c 75 65 73 2e 20 54 68 65 73 65 20 70 61 72 61 |lues. These para| 00000490 6d 65 74 65 72 73 20 61 72 65 20 61 6c 74 65 72 |meters are alter| 000004a0 65 64 0d 62 79 20 65 6e 74 65 72 69 6e 67 20 74 |ed.by entering t| 000004b0 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 |he corresponding| 000004c0 20 6e 75 6d 62 65 72 20 61 6e 64 20 74 68 65 6e | number and then| 000004d0 2c 20 69 66 20 61 20 6e 75 6d 62 65 72 20 69 73 |, if a number is| 000004e0 20 72 65 71 75 69 72 65 64 20 74 68 65 0d 75 73 | required the.us| 000004f0 65 72 20 69 73 20 70 72 6f 6d 70 74 65 64 20 74 |er is prompted t| 00000500 6f 20 65 6e 74 65 72 20 61 20 76 61 6c 75 65 2c |o enter a value,| 00000510 20 6f 74 68 65 72 77 69 73 65 20 69 66 20 74 68 | otherwise if th| 00000520 65 20 6f 70 74 69 6f 6e 20 69 73 20 6f 66 20 61 |e option is of a| 00000530 20 59 45 53 2f 4e 4f 0d 74 79 70 65 2c 20 74 68 | YES/NO.type, th| 00000540 65 20 76 61 6c 75 65 20 77 69 6c 6c 20 74 6f 67 |e value will tog| 00000550 67 6c 65 2e 20 54 68 65 20 64 65 66 61 75 6c 74 |gle. The default| 00000560 20 76 61 6c 75 65 73 20 61 72 65 20 73 75 63 68 | values are such| 00000570 20 74 68 61 74 20 74 68 65 20 62 61 6c 6c 0d 77 | that the ball.w| 00000580 69 6c 6c 20 62 65 20 74 68 72 6f 77 6e 20 75 70 |ill be thrown up| 00000590 20 69 6e 20 74 68 65 20 27 61 69 72 27 20 61 6e | in the 'air' an| 000005a0 64 20 74 68 65 6e 20 72 65 74 75 72 6e 20 74 6f |d then return to| 000005b0 20 67 72 6f 75 6e 64 2e 20 54 68 65 20 61 66 74 | ground. The aft| 000005c0 65 72 20 69 6d 61 67 65 0d 6f 66 20 74 68 65 20 |er image.of the | 000005d0 62 61 6c 6c 20 63 61 6e 20 62 65 20 74 75 72 6e |ball can be turn| 000005e0 65 64 20 6f 66 66 20 75 73 69 6e 67 20 6f 70 74 |ed off using opt| 000005f0 69 6f 6e 20 38 2c 20 61 73 20 63 61 6e 20 74 68 |ion 8, as can th| 00000600 65 20 6c 69 6e 65 20 72 65 66 65 72 65 6e 63 65 |e line reference| 00000610 73 2e 0d 41 20 66 65 77 20 70 6f 69 6e 74 73 20 |s..A few points | 00000620 6d 61 79 20 62 65 20 6e 6f 74 65 64 20 3a 0d 0d |may be noted :..| 00000630 31 2e 20 54 68 65 20 58 20 76 65 6c 6f 63 69 74 |1. The X velocit| 00000640 79 20 61 6e 64 20 74 68 65 20 59 20 76 65 6c 6f |y and the Y velo| 00000650 63 69 74 79 20 61 72 65 20 54 4f 54 41 4c 4c 59 |city are TOTALLY| 00000660 20 69 6e 64 65 70 65 6e 64 61 6e 74 20 6f 66 20 | independant of | 00000670 65 61 63 68 0d 6f 74 68 65 72 2e 0d 0d 32 2e 20 |each.other...2. | 00000680 54 68 65 20 58 20 76 65 6c 6f 63 69 74 79 20 72 |The X velocity r| 00000690 65 6d 61 69 6e 73 20 63 6f 6e 73 74 61 6e 74 20 |emains constant | 000006a0 74 68 72 6f 75 67 68 6f 75 74 20 74 68 65 20 6d |throughout the m| 000006b0 6f 74 69 6f 6e 20 62 65 63 61 75 73 65 20 74 68 |otion because th| 000006c0 65 72 65 20 69 73 0d 6e 6f 20 61 63 63 65 6c 65 |ere is.no accele| 000006d0 72 61 74 69 6f 6e 20 28 67 72 61 76 69 74 79 29 |ration (gravity)| 000006e0 20 61 63 74 69 6e 67 20 69 6e 20 74 68 65 20 58 | acting in the X| 000006f0 20 70 6c 61 6e 65 2e 0d 0d 33 2e 20 54 68 65 20 | plane...3. The | 00000700 69 6e 69 74 69 61 6c 20 59 20 76 65 6c 6f 63 69 |initial Y veloci| 00000710 74 79 20 77 69 6c 6c 2c 20 69 6e 20 67 65 6e 65 |ty will, in gene| 00000720 72 61 6c 2c 20 62 65 20 6c 61 72 67 65 20 74 6f |ral, be large to| 00000730 20 73 74 61 72 74 20 77 69 74 68 2c 20 72 65 64 | start with, red| 00000740 75 63 65 0d 61 73 20 74 68 65 20 62 61 6c 6c 20 |uce.as the ball | 00000750 67 65 74 73 20 68 69 67 68 65 72 20 75 6e 74 69 |gets higher unti| 00000760 6c 20 69 74 20 73 74 6f 70 73 2c 20 61 6e 64 20 |l it stops, and | 00000770 74 68 65 6e 20 69 74 20 77 69 6c 6c 20 62 65 67 |then it will beg| 00000780 69 6e 20 74 6f 20 67 61 69 6e 0d 73 70 65 65 64 |in to gain.speed| 00000790 20 61 73 20 69 74 20 66 61 6c 6c 73 20 62 61 63 | as it falls bac| 000007a0 6b 20 64 6f 77 6e 20 74 6f 20 74 68 65 20 67 72 |k down to the gr| 000007b0 6f 75 6e 64 2e 0d 0d 34 2e 20 42 79 20 61 6c 74 |ound...4. By alt| 000007c0 65 72 69 6e 67 20 74 68 65 20 58 20 76 65 6c 6f |ering the X velo| 000007d0 63 69 74 79 20 69 74 20 6d 61 79 20 62 65 20 73 |city it may be s| 000007e0 65 65 6e 20 74 68 61 74 20 74 68 65 20 72 61 6e |een that the ran| 000007f0 67 65 20 6f 66 20 74 68 65 20 62 61 6c 6c 20 69 |ge of the ball i| 00000800 73 0d 69 6e 63 72 65 61 73 65 64 20 62 65 63 61 |s.increased beca| 00000810 75 73 65 20 74 68 65 20 62 61 6c 6c 20 63 61 6e |use the ball can| 00000820 20 74 72 61 76 65 6c 20 66 75 72 74 68 65 72 20 | travel further | 00000830 74 6f 20 74 68 65 20 72 69 67 68 74 20 62 65 66 |to the right bef| 00000840 6f 72 65 20 69 74 0d 72 65 74 75 72 6e 73 20 74 |ore it.returns t| 00000850 6f 20 74 68 65 20 67 72 6f 75 6e 64 2e 0d 0d 54 |o the ground...T| 00000860 68 65 20 62 65 73 74 20 77 61 79 20 74 6f 20 75 |he best way to u| 00000870 6e 64 65 72 73 74 61 6e 64 20 77 68 61 74 20 69 |nderstand what i| 00000880 73 20 67 6f 69 6e 67 20 6f 6e 20 69 73 20 74 6f |s going on is to| 00000890 20 73 69 6d 70 6c 79 20 70 6c 61 79 20 77 69 74 | simply play wit| 000008a0 68 20 74 68 65 0d 70 72 6f 67 72 61 6d 2e 0d 0d |h the.program...| 000008b0 48 4f 57 20 47 52 41 56 49 54 59 20 49 53 20 53 |HOW GRAVITY IS S| 000008c0 49 4d 55 4c 41 54 45 44 0d 0d 54 68 65 20 6d 6f |IMULATED..The mo| 000008d0 76 65 6d 65 6e 74 20 6f 66 20 74 68 65 20 62 61 |vement of the ba| 000008e0 6c 6c 20 75 73 65 73 20 73 69 6d 70 6c 65 20 61 |ll uses simple a| 000008f0 6e 69 6d 61 74 69 6f 6e 20 74 65 63 68 6e 69 71 |nimation techniq| 00000900 75 65 73 2c 20 61 6e 64 20 74 68 65 0d 69 6e 74 |ues, and the.int| 00000910 72 6f 64 75 63 74 69 6f 6e 20 6f 66 20 67 72 61 |roduction of gra| 00000920 76 69 74 79 20 69 73 20 61 63 68 69 65 76 65 64 |vity is achieved| 00000930 20 6f 6e 20 6c 69 6e 65 20 33 37 30 2e 20 54 68 | on line 370. Th| 00000940 65 20 76 61 72 69 61 62 6c 65 20 27 79 76 65 6c |e variable 'yvel| 00000950 25 27 0d 68 6f 6c 64 73 20 61 20 76 61 6c 75 65 |%'.holds a value| 00000960 20 74 68 61 74 20 72 65 70 72 65 73 65 6e 74 73 | that represents| 00000970 20 74 68 65 20 59 20 76 65 6c 6f 63 69 74 79 20 | the Y velocity | 00000980 6f 66 20 74 68 65 20 62 61 6c 6c 20 69 2e 65 2e |of the ball i.e.| 00000990 20 69 74 20 69 73 20 74 68 65 0d 6e 75 6d 62 65 | it is the.numbe| 000009a0 72 20 6f 66 20 70 69 78 69 6c 73 20 77 68 69 63 |r of pixils whic| 000009b0 68 20 61 72 65 20 6a 75 6d 70 65 64 20 64 75 72 |h are jumped dur| 000009c0 69 6e 67 20 73 75 62 73 65 71 75 65 6e 74 20 70 |ing subsequent p| 000009d0 6c 6f 74 74 69 6e 67 20 6f 66 20 74 68 65 20 62 |lotting of the b| 000009e0 61 6c 6c 2e 0d 54 68 75 73 20 69 6e 69 74 69 61 |all..Thus initia| 000009f0 6c 6c 79 20 27 79 76 65 6c 25 27 20 69 73 20 6c |lly 'yvel%' is l| 00000a00 61 72 67 65 20 73 6f 20 74 68 61 74 20 74 68 65 |arge so that the| 00000a10 20 62 61 6c 6c 20 61 70 70 65 61 72 73 20 74 6f | ball appears to| 00000a20 20 6d 6f 76 65 20 66 61 73 74 2c 20 62 75 74 0d | move fast, but.| 00000a30 74 68 69 73 20 76 61 6c 75 65 20 69 73 20 73 6c |this value is sl| 00000a40 6f 77 6c 79 20 64 65 63 72 65 61 73 65 64 20 62 |owly decreased b| 00000a50 79 20 73 75 62 74 72 61 63 74 69 6e 67 20 61 20 |y subtracting a | 00000a60 76 61 6c 75 65 20 68 65 6c 64 20 69 6e 20 27 67 |value held in 'g| 00000a70 72 61 76 69 74 79 27 20 73 6f 0d 74 68 61 74 20 |ravity' so.that | 00000a80 74 68 65 20 62 61 6c 6c 20 61 70 70 65 61 72 73 |the ball appears| 00000a90 20 74 6f 20 73 6c 6f 77 20 64 6f 77 6e 20 61 73 | to slow down as| 00000aa0 20 69 74 20 67 65 74 73 20 68 69 67 68 65 72 2e | it gets higher.| 00000ab0 20 45 76 65 6e 74 75 61 6c 6c 79 20 27 79 76 65 | Eventually 'yve| 00000ac0 6c 25 27 0d 77 69 6c 6c 20 62 65 63 6f 6d 65 20 |l%'.will become | 00000ad0 7a 65 72 6f 2c 20 61 66 74 65 72 77 68 69 63 68 |zero, afterwhich| 00000ae0 20 69 74 20 77 69 6c 6c 20 62 65 63 6f 6d 65 20 | it will become | 00000af0 6e 65 67 61 74 69 76 65 20 28 69 2e 65 2e 20 61 |negative (i.e. a| 00000b00 20 2d 76 65 0d 76 65 6c 6f 63 69 74 79 29 2c 20 | -ve.velocity), | 00000b10 73 6f 20 74 68 65 20 62 61 6c 6c 20 77 69 6c 6c |so the ball will| 00000b20 20 73 6c 6f 77 6c 79 20 62 65 67 69 6e 20 74 6f | slowly begin to| 00000b30 20 6d 6f 76 65 20 69 6e 20 74 68 65 20 6f 70 70 | move in the opp| 00000b40 6f 73 69 74 65 20 64 69 72 65 63 74 69 6f 6e 0d |osite direction.| 00000b50 61 6e 64 20 74 68 65 6e 20 67 61 74 68 65 72 20 |and then gather | 00000b60 73 70 65 65 64 2e 20 54 68 65 20 76 61 72 69 61 |speed. The varia| 00000b70 62 6c 65 20 27 67 72 61 76 69 74 79 27 20 72 65 |ble 'gravity' re| 00000b80 70 72 65 73 65 6e 74 73 20 74 68 65 20 72 61 74 |presents the rat| 00000b90 65 20 6f 66 0d 63 68 61 6e 67 65 20 6f 66 20 74 |e of.change of t| 00000ba0 68 65 20 59 20 76 65 6c 6f 63 69 74 79 20 28 69 |he Y velocity (i| 00000bb0 74 73 20 61 63 63 65 6c 65 72 61 74 69 6f 6e 2c |ts acceleration,| 00000bc0 20 6f 72 20 27 74 68 65 20 67 72 61 76 69 74 61 | or 'the gravita| 00000bd0 74 69 6f 6e 61 6c 20 66 69 65 6c 64 0d 73 74 72 |tional field.str| 00000be0 65 6e 67 74 68 27 29 2e 0d 0d 43 49 52 43 55 4c |ength')...CIRCUL| 00000bf0 41 52 20 4d 4f 54 49 4f 4e 20 41 4e 44 20 47 52 |AR MOTION AND GR| 00000c00 41 56 49 54 59 20 2d 20 74 68 65 20 70 65 6e 64 |AVITY - the pend| 00000c10 75 6c 75 6d 0d 0d 57 68 65 6e 20 62 6f 64 69 65 |ulum..When bodie| 00000c20 73 20 6d 6f 76 65 20 75 6e 64 65 72 20 74 68 65 |s move under the| 00000c30 20 69 6e 66 6c 75 65 6e 63 65 20 6f 66 20 67 72 | influence of gr| 00000c40 61 76 69 74 79 20 61 6e 64 20 61 72 65 20 61 6c |avity and are al| 00000c50 73 6f 20 65 66 66 65 63 74 65 64 20 62 79 0d 61 |so effected by.a| 00000c60 6e 20 65 78 74 65 72 6e 61 6c 20 66 6f 72 63 65 |n external force| 00000c70 20 69 74 20 62 65 63 6f 6d 65 73 20 6d 6f 72 65 | it becomes more| 00000c80 20 64 69 66 66 69 63 75 6c 74 20 74 6f 20 73 69 | difficult to si| 00000c90 6d 75 6c 61 74 65 20 74 68 65 69 72 20 6d 6f 74 |mulate their mot| 00000ca0 69 6f 6e 20 6f 6e 20 61 0d 63 6f 6d 70 75 74 65 |ion on a.compute| 00000cb0 72 2c 20 62 75 74 20 74 68 65 20 73 65 63 72 65 |r, but the secre| 00000cc0 74 20 69 73 20 74 6f 20 74 61 6b 65 20 65 61 63 |t is to take eac| 00000cd0 68 20 66 6f 72 63 65 20 69 6e 20 74 75 72 6e 20 |h force in turn | 00000ce0 61 6e 64 20 70 72 6f 67 72 61 6d 20 74 68 65 0d |and program the.| 00000cf0 65 66 66 65 63 74 73 20 74 68 61 74 20 74 68 65 |effects that the| 00000d00 73 65 20 66 6f 72 63 65 73 20 77 69 6c 6c 20 68 |se forces will h| 00000d10 61 76 65 20 6f 6e 20 74 68 65 20 62 6f 64 79 20 |ave on the body | 00000d20 6f 6e 65 20 61 74 20 61 20 74 69 6d 65 2e 20 46 |one at a time. F| 00000d30 6f 72 0d 65 78 61 6d 70 6c 65 2c 20 61 20 74 72 |or.example, a tr| 00000d40 75 65 20 70 65 6e 64 75 6c 75 6d 20 62 6f 62 20 |ue pendulum bob | 00000d50 6d 6f 76 65 73 20 69 6e 20 61 20 63 69 72 63 6c |moves in a circl| 00000d60 75 6c 61 72 20 61 72 63 20 61 6e 64 20 69 73 20 |ular arc and is | 00000d70 65 66 66 65 63 74 65 64 20 62 79 0d 67 72 61 76 |effected by.grav| 00000d80 69 74 79 2c 20 72 65 73 75 6c 74 69 6e 67 20 69 |ity, resulting i| 00000d90 6e 20 6f 73 63 69 6c 6c 61 74 69 6f 6e 73 20 6f |n oscillations o| 00000da0 66 20 74 68 65 20 70 65 6e 64 75 6c 75 6d 2e 20 |f the pendulum. | 00000db0 54 68 69 73 20 63 61 6e 20 62 65 20 73 69 6d 75 |This can be simu| 00000dc0 6c 61 74 65 64 0d 6f 6e 20 61 20 63 6f 6d 70 75 |lated.on a compu| 00000dd0 74 65 72 20 62 79 20 66 69 72 73 74 6c 79 20 6d |ter by firstly m| 00000de0 61 6b 69 6e 67 20 61 20 62 61 6c 6c 20 6d 6f 76 |aking a ball mov| 00000df0 65 20 69 6e 20 61 20 63 69 72 63 6c 65 20 6f 6e |e in a circle on| 00000e00 20 74 68 65 20 73 63 72 65 65 6e 20 61 6e 64 0d | the screen and.| 00000e10 74 68 65 6e 2c 20 61 73 20 73 65 65 6e 20 69 6e |then, as seen in| 00000e20 20 70 72 6f 67 72 61 6d 20 31 2c 20 69 74 20 69 | program 1, it i| 00000e30 73 20 73 69 6d 70 6c 79 20 61 20 6d 61 74 74 65 |s simply a matte| 00000e40 72 20 6f 66 20 61 6c 74 65 72 69 6e 67 20 74 68 |r of altering th| 00000e50 65 20 76 65 6c 6f 63 69 74 79 0d 6f 66 20 74 68 |e velocity.of th| 00000e60 65 20 62 6f 62 20 61 74 20 64 69 66 66 65 72 65 |e bob at differe| 00000e70 6e 74 20 73 74 61 67 65 73 20 6f 66 20 69 74 73 |nt stages of its| 00000e80 20 6d 6f 74 69 6f 6e 2e 0d 0d 50 72 6f 67 72 61 | motion...Progra| 00000e90 6d 20 32 20 73 69 6d 75 6c 61 74 65 73 20 74 72 |m 2 simulates tr| 00000ea0 75 65 20 70 65 6e 64 75 6c 75 6d 20 6d 6f 74 69 |ue pendulum moti| 00000eb0 6f 6e 2e 20 49 74 20 77 61 73 20 77 72 69 74 74 |on. It was writt| 00000ec0 65 6e 20 62 79 20 66 69 72 73 74 6c 79 0d 6f 62 |en by firstly.ob| 00000ed0 74 61 69 6e 69 6e 67 20 61 20 63 69 72 63 6c 65 |taining a circle| 00000ee0 20 66 75 6e 63 74 69 6f 6e 20 28 75 73 69 6e 67 | function (using| 00000ef0 20 74 77 6f 20 53 49 4e 45 20 77 61 76 65 73 20 | two SINE waves | 00000f00 39 30 20 64 65 67 72 65 65 73 20 6f 75 74 20 6f |90 degrees out o| 00000f10 66 20 70 68 61 73 65 0d 2d 20 64 6f 6e 27 74 20 |f phase.- don't | 00000f20 77 6f 72 72 79 20 61 62 6f 75 74 20 74 68 69 73 |worry about this| 00000f30 29 2c 20 61 6e 64 20 74 68 65 6e 20 6d 61 6b 69 |), and then maki| 00000f40 6e 67 20 61 20 67 72 61 70 68 69 63 20 63 68 61 |ng a graphic cha| 00000f50 72 61 63 74 65 72 20 6d 6f 76 65 20 69 6e 0d 74 |racter move in.t| 00000f60 68 69 73 20 63 69 72 63 6c 65 2e 20 48 61 76 69 |his circle. Havi| 00000f70 6e 67 20 61 63 68 69 65 76 65 64 20 74 68 69 73 |ng achieved this| 00000f80 2c 20 74 68 65 20 69 6e 69 74 69 61 6c 20 70 6f |, the initial po| 00000f90 73 69 74 69 6f 6e 20 6f 66 20 74 68 65 20 62 6f |sition of the bo| 00000fa0 62 20 69 73 0d 64 65 63 69 64 65 64 20 61 6e 64 |b is.decided and| 00000fb0 20 74 68 65 6e 20 74 68 65 20 70 65 6e 64 75 6c | then the pendul| 00000fc0 75 6d 20 69 73 20 61 6c 6c 6f 77 65 64 20 74 6f |um is allowed to| 00000fd0 20 72 6f 74 61 74 65 20 69 6e 20 61 20 63 69 72 | rotate in a cir| 00000fe0 63 75 6c 61 72 20 70 61 74 68 0d 69 6e 69 74 69 |cular path.initi| 00000ff0 61 6c 6c 79 20 6d 6f 76 69 6e 67 20 64 6f 77 6e |ally moving down| 00001000 77 61 72 64 73 2e 20 54 68 65 20 70 72 6f 63 65 |wards. The proce| 00001010 64 75 72 65 20 27 78 79 27 20 63 61 6c 63 75 6c |dure 'xy' calcul| 00001020 61 74 65 73 20 74 68 65 20 78 2d 79 20 70 6f 73 |ates the x-y pos| 00001030 69 74 69 6f 6e 0d 6f 66 20 74 68 65 20 62 6f 62 |ition.of the bob| 00001040 20 61 74 20 61 6e 79 20 61 6e 67 6c 65 20 28 68 | at any angle (h| 00001050 65 6c 64 20 69 6e 20 27 70 6f 73 27 29 20 6f 66 |eld in 'pos') of| 00001060 20 74 68 65 20 63 69 72 63 6c 65 2e 20 54 68 75 | the circle. Thu| 00001070 73 2c 20 74 6f 20 6f 62 74 61 69 6e 0d 63 69 72 |s, to obtain.cir| 00001080 63 75 6c 65 72 20 6d 6f 74 69 6f 6e 20 69 74 20 |culer motion it | 00001090 69 73 20 73 69 6d 70 6c 79 20 61 20 6d 61 74 74 |is simply a matt| 000010a0 65 72 20 6f 66 20 67 69 76 69 6e 67 20 27 70 6f |er of giving 'po| 000010b0 73 27 20 63 6f 6e 73 65 63 75 74 69 76 65 20 76 |s' consecutive v| 000010c0 61 6c 75 65 73 0d 66 72 6f 6d 20 30 20 74 6f 20 |alues.from 0 to | 000010d0 33 36 30 20 64 67 72 65 65 73 20 61 6e 64 20 70 |360 dgrees and p| 000010e0 6c 6f 74 74 69 6e 67 20 65 61 63 68 20 78 2d 79 |lotting each x-y| 000010f0 20 63 6f 72 72 64 69 6e 61 74 65 20 66 6f 72 20 | corrdinate for | 00001100 74 68 65 0d 63 6f 72 72 65 73 70 6f 6e 64 69 6e |the.correspondin| 00001110 67 20 76 61 6c 75 65 20 6f 66 20 27 70 6f 73 27 |g value of 'pos'| 00001120 2e 0d 0d 48 6f 77 65 76 65 72 2c 20 77 65 20 77 |...However, we w| 00001130 61 6e 74 20 74 68 65 20 70 65 6e 64 75 6c 75 6d |ant the pendulum| 00001140 20 74 6f 20 73 74 61 72 74 20 66 72 6f 6d 20 61 | to start from a| 00001150 20 68 6f 72 69 7a 6f 6e 74 61 6c 20 70 6f 73 69 | horizontal posi| 00001160 74 69 6f 6e 2c 20 73 6f 20 74 68 65 0d 69 6e 69 |tion, so the.ini| 00001170 74 69 61 6c 20 76 61 6c 75 65 20 6f 66 20 27 70 |tial value of 'p| 00001180 6f 73 27 20 69 73 20 73 65 74 20 74 6f 20 39 30 |os' is set to 90| 00001190 20 64 65 67 72 65 65 73 20 28 6c 69 6e 65 20 32 | degrees (line 2| 000011a0 34 30 29 2e 20 54 68 65 20 73 70 65 65 64 20 6f |40). The speed o| 000011b0 66 20 74 68 65 0d 62 6f 62 20 69 73 20 64 65 74 |f the.bob is det| 000011c0 65 72 6d 69 6e 65 64 20 62 79 20 74 68 65 20 73 |ermined by the s| 000011d0 74 65 70 20 72 61 74 65 20 6f 66 20 74 68 65 20 |tep rate of the | 000011e0 61 6e 67 6c 65 20 74 68 72 6f 75 67 68 20 77 68 |angle through wh| 000011f0 69 63 68 20 74 68 65 20 62 6f 62 0d 74 75 72 6e |ich the bob.turn| 00001200 73 20 28 69 2e 65 2e 20 74 68 65 20 72 61 74 65 |s (i.e. the rate| 00001210 20 6f 66 20 63 68 61 6e 67 65 20 6f 66 20 27 70 | of change of 'p| 00001220 6f 73 27 29 2e 20 54 68 69 73 20 73 74 65 70 20 |os'). This step | 00001230 72 61 74 65 20 69 73 20 68 65 6c 64 20 69 6e 20 |rate is held in | 00001240 74 68 65 0d 76 61 72 69 61 62 6c 65 20 27 76 65 |the.variable 've| 00001250 6c 27 20 73 6f 20 69 66 2c 20 66 6f 72 20 65 78 |l' so if, for ex| 00001260 61 6d 70 6c 65 2c 20 27 76 65 6c 27 20 3d 20 31 |ample, 'vel' = 1| 00001270 30 2c 20 74 68 65 6e 20 74 68 65 20 62 6f 62 20 |0, then the bob | 00001280 77 6f 75 6c 64 20 6d 6f 76 65 20 69 6e 0d 61 20 |would move in.a | 00001290 63 69 72 63 6c 65 20 69 6e 20 6a 75 6d 70 73 20 |circle in jumps | 000012a0 6f 66 20 31 30 20 64 65 67 72 65 65 73 2e 20 49 |of 10 degrees. I| 000012b0 74 20 69 73 20 6e 6f 77 20 61 20 73 69 6d 70 6c |t is now a simpl| 000012c0 65 20 6d 61 74 74 65 72 20 74 6f 20 69 6e 74 72 |e matter to intr| 000012d0 6f 64 75 63 65 0d 67 72 61 76 69 74 79 20 28 61 |oduce.gravity (a| 000012e0 73 20 77 65 20 64 69 64 20 69 6e 20 70 72 6f 67 |s we did in prog| 000012f0 72 61 6d 20 31 20 29 20 62 79 20 69 6e 63 72 65 |ram 1 ) by incre| 00001300 61 73 69 6e 67 20 74 68 65 20 76 65 6c 6f 63 69 |asing the veloci| 00001310 74 79 20 6f 66 20 74 68 65 20 62 6f 62 20 61 73 |ty of the bob as| 00001320 0d 69 74 20 66 61 6c 6c 73 2e 20 54 68 69 73 20 |.it falls. This | 00001330 69 73 20 61 63 68 69 65 76 65 64 20 6f 6e 20 6c |is achieved on l| 00001340 69 6e 65 20 33 36 30 2e 0d 0d 54 68 65 72 65 20 |ine 360...There | 00001350 69 73 2c 20 68 6f 77 65 76 65 72 2c 20 6f 6e 65 |is, however, one| 00001360 20 70 72 6f 62 6c 65 6d 2e 20 42 65 63 61 75 73 | problem. Becaus| 00001370 65 20 74 68 65 20 76 65 6c 6f 63 69 74 79 20 69 |e the velocity i| 00001380 73 20 63 6f 6e 73 74 61 6e 74 6c 79 0d 69 6e 63 |s constantly.inc| 00001390 72 65 61 73 69 6e 67 20 66 72 6f 6d 20 61 20 70 |reasing from a p| 000013a0 6f 73 69 74 69 76 65 20 76 61 6c 75 65 20 61 73 |ositive value as| 000013b0 20 69 74 20 73 77 69 6e 67 73 20 64 6f 77 6e 77 | it swings downw| 000013c0 61 72 64 73 2c 20 69 74 20 77 69 6c 6c 20 6e 65 |ards, it will ne| 000013d0 76 65 72 0d 72 65 61 63 68 20 61 20 74 75 72 6e |ver.reach a turn| 000013e0 69 6e 67 20 70 6f 69 6e 74 20 61 74 20 77 68 69 |ing point at whi| 000013f0 63 68 20 74 68 65 20 76 65 6c 6f 63 69 74 79 20 |ch the velocity | 00001400 77 69 6c 6c 20 62 65 67 69 6e 20 74 6f 20 67 65 |will begin to ge| 00001410 74 20 73 6c 6f 77 65 72 2c 20 73 6f 0d 74 68 65 |t slower, so.the| 00001420 20 72 65 73 75 6c 74 20 77 69 6c 6c 20 62 65 20 | result will be | 00001430 61 20 63 6f 6e 73 74 61 6e 74 6c 79 20 61 63 63 |a constantly acc| 00001440 65 6c 65 72 61 74 69 6e 67 20 62 6f 62 20 6d 6f |elerating bob mo| 00001450 76 69 6e 67 20 69 6e 20 61 20 63 69 72 63 6c 65 |ving in a circle| 00001460 2e 20 54 68 75 73 0d 77 65 20 6d 75 73 74 20 70 |. Thus.we must p| 00001470 75 74 20 69 6e 20 61 20 63 6f 6e 64 69 74 69 6f |ut in a conditio| 00001480 6e 20 77 68 65 72 65 62 79 20 6f 6e 63 65 20 74 |n whereby once t| 00001490 68 65 20 62 6f 62 20 72 65 61 63 68 65 73 20 61 |he bob reaches a| 000014a0 20 63 65 72 74 61 69 6e 0d 76 65 6c 6f 63 69 74 | certain.velocit| 000014b0 79 2c 20 74 68 65 20 73 69 67 6e 20 6f 66 20 74 |y, the sign of t| 000014c0 68 65 20 67 72 61 76 69 74 79 20 69 73 20 63 68 |he gravity is ch| 000014d0 61 6e 67 65 64 20 72 65 73 75 6c 74 69 6e 67 20 |anged resulting | 000014e0 69 6e 20 74 68 65 20 62 6f 62 20 73 6c 6f 77 69 |in the bob slowi| 000014f0 6e 67 0d 64 6f 77 6e 20 75 6e 74 69 6c 20 69 74 |ng.down until it| 00001500 20 65 76 65 6e 74 75 61 6c 6c 79 20 73 74 6f 70 | eventually stop| 00001510 73 20 61 74 20 74 68 65 20 74 6f 70 20 6f 66 20 |s at the top of | 00001520 69 74 73 20 73 77 69 6e 67 20 28 73 65 65 20 6c |its swing (see l| 00001530 69 6e 65 73 0d 33 34 30 2c 33 35 30 29 2e 20 41 |ines.340,350). A| 00001540 6c 74 65 72 6e 61 74 69 76 65 6c 79 2c 20 74 68 |lternatively, th| 00001550 65 20 73 69 67 6e 20 6f 66 20 27 67 72 61 76 69 |e sign of 'gravi| 00001560 74 79 27 20 63 6f 75 6c 64 20 62 65 20 73 77 61 |ty' could be swa| 00001570 70 70 65 64 20 77 68 65 6e 20 74 68 65 0d 76 61 |pped when the.va| 00001580 6c 75 65 20 6f 66 20 27 70 6f 73 27 20 65 71 75 |lue of 'pos' equ| 00001590 61 6c 65 64 20 31 38 30 20 64 65 67 72 65 65 73 |aled 180 degrees| 000015a0 2c 20 62 75 74 20 79 6f 75 20 68 61 76 65 20 74 |, but you have t| 000015b0 6f 20 6d 61 6b 65 20 73 75 72 65 20 74 68 61 74 |o make sure that| 000015c0 20 27 70 6f 73 27 0d 64 6f 65 73 20 61 63 74 75 | 'pos'.does actu| 000015d0 61 6c 6c 79 20 62 65 63 6f 6d 65 20 65 78 61 63 |ally become exac| 000015e0 74 6c 79 20 31 38 30 20 64 65 67 72 65 65 73 20 |tly 180 degrees | 000015f0 61 74 20 73 6f 6d 65 20 70 6f 69 6e 74 20 6f 66 |at some point of| 00001600 20 74 68 65 20 73 77 69 6e 67 2e 0d 0d 52 4f 42 | the swing...ROB| 00001610 20 41 4e 44 45 52 53 4f 4e 2e 20 53 45 50 54 45 | ANDERSON. SEPTE| 00001620 4d 42 45 52 20 31 39 38 36 20 0d |MBER 1986 .| 0000162b