Home » Personal collection » Acorn DFS disks » dfs_box03_disk13_bcpl_calc.scp » EXSPIRB
EXSPIRB
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 » Personal collection » Acorn DFS disks » dfs_box03_disk13_bcpl_calc.scp |
Filename: | EXSPIRB |
Read OK: | ✔ |
File size: | 0ACA bytes |
Load address: | FF1122 |
Exec address: | 20007 |
File contents
SECTION "EXSPIRB" // Example program to draw a spiral using the fast integer procedures. // The fast integer procedures are // copyright Richards Computer Products Ltd. (C) 1983 // Written by C Jobson 22/04/83 // The program is based on the program 'SPIRAL1' in the book 'Creative // Graphics on the BBC Microcomputer' by J Cownie published by // Acornsoft Ltd. NEEDS "VDU" NEEDS "TIME" GET "LIBHDR" GET "FPHDR" MANIFEST $( PI = 31416 $) // Draws a flat spiral with palette changes giving the effect of // movement. LET START() BE $( LET C = 1 // used to keep track of palette LET A = 0 // angle // Enter screen mode 1, hide the cursor, set the graphics origin in // the centre of the screen and move to the origin. UNLESS MODE(1) DO $( WRITES("Not enough free heap space to enter*N* *screen mode 1. Please SHUFFLE and*N* *try again.*N") STOP(RESULT2) $) VDU("5,29,640;512;25,4,0;0;") // Enter loop to calculate next point and draw a line to it. Loop // is performed 1500 times and increments A by 2000 each time. // Thus with scaling of 10000 this represents A going from 0 to 300 // radians in steps of 0.2 radians. FOR I = 0 TO 1500 $( // Choose logical colour 1, 2 or 3 using formula corresponding // to '1+(3.8*A REM 3)'. Note that since A is incremented by // 0.2 (i.e. 2000) each time I is incremented by 1, I is // equivalent to 5*A and thus the formula becomes '1+(0.76*I REM // 3)' and 0.76 = 19/25. The factor of 3.8 makes the arms // reasonably straight. VDU("18,0,%", 1+( ((19*I+12)/25) REM 3) ) // Draw to next point whose coordinates are 3*A*SIN(A) and // 2*A*COS(A). Since SIN(A) and COS(A) are scaled by 10000 use // MULDIV with I/5 instead of A in the multiplication. VDU("25,5,%;%;", MULDIV(SIN(A), (3*I+2)/5, 10000), MULDIV(COS(A), (2*I+2)/5, 10000) ) // Increment A by 2000 (representing 0.2) wrapping round from pi // to -pi. TEST A > PI-2000 THEN A := A+2000-(2*PI) ELSE A := A+2000 // Change the palette every 4th point. Use actual colours 3, 4 // and 5 (yellow, blue and magenta). IF (I & 3) = 0 DO $( FOR J = 1 TO 3 VDU("19,%,%;%;", J, ((C+J) REM 3)+3, 0) C := (C+1) REM 3 // so next palette change moves colours on one // step $) $) // Wait for 5 seconds then go back to mode 7. $( LET T = TIME()+500 IF T < 0 THEN T := T+#X8000 // compensate for wrapround UNTIL TIME() = T LOOP MODE(7) $) $)
00000000 53 45 43 54 49 4f 4e 20 22 45 58 53 50 49 52 42 |SECTION "EXSPIRB| 00000010 22 0d 0a 0d 0a 2f 2f 20 45 78 61 6d 70 6c 65 20 |"....// Example | 00000020 70 72 6f 67 72 61 6d 20 74 6f 20 64 72 61 77 20 |program to draw | 00000030 61 20 73 70 69 72 61 6c 20 75 73 69 6e 67 20 74 |a spiral using t| 00000040 68 65 20 66 61 73 74 20 69 6e 74 65 67 65 72 20 |he fast integer | 00000050 70 72 6f 63 65 64 75 72 65 73 2e 0d 0a 2f 2f 20 |procedures...// | 00000060 54 68 65 20 66 61 73 74 20 69 6e 74 65 67 65 72 |The fast integer| 00000070 20 70 72 6f 63 65 64 75 72 65 73 20 61 72 65 0d | procedures are.| 00000080 0a 2f 2f 20 63 6f 70 79 72 69 67 68 74 20 52 69 |.// copyright Ri| 00000090 63 68 61 72 64 73 20 43 6f 6d 70 75 74 65 72 20 |chards Computer | 000000a0 50 72 6f 64 75 63 74 73 20 4c 74 64 2e 20 28 43 |Products Ltd. (C| 000000b0 29 20 31 39 38 33 0d 0a 2f 2f 20 57 72 69 74 74 |) 1983..// Writt| 000000c0 65 6e 20 62 79 20 43 20 4a 6f 62 73 6f 6e 20 32 |en by C Jobson 2| 000000d0 32 2f 30 34 2f 38 33 0d 0a 0d 0a 2f 2f 20 54 68 |2/04/83....// Th| 000000e0 65 20 70 72 6f 67 72 61 6d 20 69 73 20 62 61 73 |e program is bas| 000000f0 65 64 20 6f 6e 20 74 68 65 20 70 72 6f 67 72 61 |ed on the progra| 00000100 6d 20 27 53 50 49 52 41 4c 31 27 20 69 6e 20 74 |m 'SPIRAL1' in t| 00000110 68 65 20 62 6f 6f 6b 20 27 43 72 65 61 74 69 76 |he book 'Creativ| 00000120 65 0d 0a 2f 2f 20 47 72 61 70 68 69 63 73 20 6f |e..// Graphics o| 00000130 6e 20 74 68 65 20 42 42 43 20 4d 69 63 72 6f 63 |n the BBC Microc| 00000140 6f 6d 70 75 74 65 72 27 20 62 79 20 4a 20 43 6f |omputer' by J Co| 00000150 77 6e 69 65 20 70 75 62 6c 69 73 68 65 64 20 62 |wnie published b| 00000160 79 0d 0a 2f 2f 20 41 63 6f 72 6e 73 6f 66 74 20 |y..// Acornsoft | 00000170 4c 74 64 2e 0d 0a 0d 0a 4e 45 45 44 53 20 22 56 |Ltd.....NEEDS "V| 00000180 44 55 22 0d 0a 4e 45 45 44 53 20 22 54 49 4d 45 |DU"..NEEDS "TIME| 00000190 22 0d 0a 47 45 54 20 22 4c 49 42 48 44 52 22 0d |"..GET "LIBHDR".| 000001a0 0a 47 45 54 20 22 46 50 48 44 52 22 0d 0a 0d 0a |.GET "FPHDR"....| 000001b0 4d 41 4e 49 46 45 53 54 20 24 28 20 50 49 20 3d |MANIFEST $( PI =| 000001c0 20 33 31 34 31 36 20 24 29 0d 0a 0d 0a 0d 0a 2f | 31416 $)....../| 000001d0 2f 20 44 72 61 77 73 20 61 20 66 6c 61 74 20 73 |/ Draws a flat s| 000001e0 70 69 72 61 6c 20 77 69 74 68 20 70 61 6c 65 74 |piral with palet| 000001f0 74 65 20 63 68 61 6e 67 65 73 20 67 69 76 69 6e |te changes givin| 00000200 67 20 74 68 65 20 65 66 66 65 63 74 20 6f 66 0d |g the effect of.| 00000210 0a 2f 2f 20 6d 6f 76 65 6d 65 6e 74 2e 0d 0a 0d |.// movement....| 00000220 0a 4c 45 54 20 53 54 41 52 54 28 29 20 42 45 0d |.LET START() BE.| 00000230 0a 24 28 20 4c 45 54 20 43 20 3d 20 31 20 20 20 |.$( LET C = 1 | 00000240 20 20 20 2f 2f 20 75 73 65 64 20 74 6f 20 6b 65 | // used to ke| 00000250 65 70 20 74 72 61 63 6b 20 6f 66 20 70 61 6c 65 |ep track of pale| 00000260 74 74 65 0d 0a 20 20 20 4c 45 54 20 41 20 3d 20 |tte.. LET A = | 00000270 30 20 20 20 20 20 20 2f 2f 20 61 6e 67 6c 65 0d |0 // angle.| 00000280 0a 0d 0a 20 20 20 2f 2f 20 45 6e 74 65 72 20 73 |... // Enter s| 00000290 63 72 65 65 6e 20 6d 6f 64 65 20 31 2c 20 68 69 |creen mode 1, hi| 000002a0 64 65 20 74 68 65 20 63 75 72 73 6f 72 2c 20 73 |de the cursor, s| 000002b0 65 74 20 74 68 65 20 67 72 61 70 68 69 63 73 20 |et the graphics | 000002c0 6f 72 69 67 69 6e 20 69 6e 0d 0a 20 20 20 2f 2f |origin in.. //| 000002d0 20 74 68 65 20 63 65 6e 74 72 65 20 6f 66 20 74 | the centre of t| 000002e0 68 65 20 73 63 72 65 65 6e 20 61 6e 64 20 6d 6f |he screen and mo| 000002f0 76 65 20 74 6f 20 74 68 65 20 6f 72 69 67 69 6e |ve to the origin| 00000300 2e 0d 0a 0d 0a 20 20 20 55 4e 4c 45 53 53 20 4d |..... UNLESS M| 00000310 4f 44 45 28 31 29 20 44 4f 0d 0a 20 20 20 24 28 |ODE(1) DO.. $(| 00000320 20 57 52 49 54 45 53 28 22 4e 6f 74 20 65 6e 6f | WRITES("Not eno| 00000330 75 67 68 20 66 72 65 65 20 68 65 61 70 20 73 70 |ugh free heap sp| 00000340 61 63 65 20 74 6f 20 65 6e 74 65 72 2a 4e 2a 0d |ace to enter*N*.| 00000350 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 73 |. *s| 00000360 63 72 65 65 6e 20 6d 6f 64 65 20 31 2e 20 20 50 |creen mode 1. P| 00000370 6c 65 61 73 65 20 53 48 55 46 46 4c 45 20 61 6e |lease SHUFFLE an| 00000380 64 2a 4e 2a 0d 0a 20 20 20 20 20 20 20 20 20 20 |d*N*.. | 00000390 20 20 20 2a 74 72 79 20 61 67 61 69 6e 2e 2a 4e | *try again.*N| 000003a0 22 29 0d 0a 20 20 20 20 20 20 53 54 4f 50 28 52 |").. STOP(R| 000003b0 45 53 55 4c 54 32 29 0d 0a 20 20 20 24 29 0d 0a |ESULT2).. $)..| 000003c0 20 20 20 56 44 55 28 22 35 2c 32 39 2c 36 34 30 | VDU("5,29,640| 000003d0 3b 35 31 32 3b 32 35 2c 34 2c 30 3b 30 3b 22 29 |;512;25,4,0;0;")| 000003e0 0d 0a 0d 0a 20 20 20 2f 2f 20 45 6e 74 65 72 20 |.... // Enter | 000003f0 6c 6f 6f 70 20 74 6f 20 63 61 6c 63 75 6c 61 74 |loop to calculat| 00000400 65 20 6e 65 78 74 20 70 6f 69 6e 74 20 61 6e 64 |e next point and| 00000410 20 64 72 61 77 20 61 20 6c 69 6e 65 20 74 6f 20 | draw a line to | 00000420 69 74 2e 20 20 4c 6f 6f 70 0d 0a 20 20 20 2f 2f |it. Loop.. //| 00000430 20 69 73 20 70 65 72 66 6f 72 6d 65 64 20 31 35 | is performed 15| 00000440 30 30 20 74 69 6d 65 73 20 61 6e 64 20 69 6e 63 |00 times and inc| 00000450 72 65 6d 65 6e 74 73 20 41 20 62 79 20 32 30 30 |rements A by 200| 00000460 30 20 65 61 63 68 20 74 69 6d 65 2e 0d 0a 20 20 |0 each time... | 00000470 20 2f 2f 20 54 68 75 73 20 77 69 74 68 20 73 63 | // Thus with sc| 00000480 61 6c 69 6e 67 20 6f 66 20 31 30 30 30 30 20 74 |aling of 10000 t| 00000490 68 69 73 20 72 65 70 72 65 73 65 6e 74 73 20 41 |his represents A| 000004a0 20 67 6f 69 6e 67 20 66 72 6f 6d 20 30 20 74 6f | going from 0 to| 000004b0 20 33 30 30 0d 0a 20 20 20 2f 2f 20 72 61 64 69 | 300.. // radi| 000004c0 61 6e 73 20 69 6e 20 73 74 65 70 73 20 6f 66 20 |ans in steps of | 000004d0 30 2e 32 20 72 61 64 69 61 6e 73 2e 0d 0a 0d 0a |0.2 radians.....| 000004e0 20 20 20 46 4f 52 20 49 20 3d 20 30 20 54 4f 20 | FOR I = 0 TO | 000004f0 31 35 30 30 0d 0a 20 20 20 24 28 0d 0a 20 20 20 |1500.. $(.. | 00000500 20 20 20 2f 2f 20 43 68 6f 6f 73 65 20 6c 6f 67 | // Choose log| 00000510 69 63 61 6c 20 63 6f 6c 6f 75 72 20 31 2c 20 32 |ical colour 1, 2| 00000520 20 6f 72 20 33 20 75 73 69 6e 67 20 66 6f 72 6d | or 3 using form| 00000530 75 6c 61 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e |ula correspondin| 00000540 67 0d 0a 20 20 20 20 20 20 2f 2f 20 74 6f 20 27 |g.. // to '| 00000550 31 2b 28 33 2e 38 2a 41 20 52 45 4d 20 33 29 27 |1+(3.8*A REM 3)'| 00000560 2e 20 20 4e 6f 74 65 20 74 68 61 74 20 73 69 6e |. Note that sin| 00000570 63 65 20 41 20 69 73 20 69 6e 63 72 65 6d 65 6e |ce A is incremen| 00000580 74 65 64 20 62 79 0d 0a 20 20 20 20 20 20 2f 2f |ted by.. //| 00000590 20 30 2e 32 20 28 69 2e 65 2e 20 32 30 30 30 29 | 0.2 (i.e. 2000)| 000005a0 20 65 61 63 68 20 74 69 6d 65 20 49 20 69 73 20 | each time I is | 000005b0 69 6e 63 72 65 6d 65 6e 74 65 64 20 62 79 20 31 |incremented by 1| 000005c0 2c 20 49 20 69 73 0d 0a 20 20 20 20 20 20 2f 2f |, I is.. //| 000005d0 20 65 71 75 69 76 61 6c 65 6e 74 20 74 6f 20 35 | equivalent to 5| 000005e0 2a 41 20 61 6e 64 20 74 68 75 73 20 74 68 65 20 |*A and thus the | 000005f0 66 6f 72 6d 75 6c 61 20 62 65 63 6f 6d 65 73 20 |formula becomes | 00000600 27 31 2b 28 30 2e 37 36 2a 49 20 52 45 4d 0d 0a |'1+(0.76*I REM..| 00000610 20 20 20 20 20 20 2f 2f 20 33 29 27 20 61 6e 64 | // 3)' and| 00000620 20 30 2e 37 36 20 3d 20 31 39 2f 32 35 2e 20 20 | 0.76 = 19/25. | 00000630 54 68 65 20 66 61 63 74 6f 72 20 6f 66 20 33 2e |The factor of 3.| 00000640 38 20 6d 61 6b 65 73 20 74 68 65 20 61 72 6d 73 |8 makes the arms| 00000650 0d 0a 20 20 20 20 20 20 2f 2f 20 72 65 61 73 6f |.. // reaso| 00000660 6e 61 62 6c 79 20 73 74 72 61 69 67 68 74 2e 0d |nably straight..| 00000670 0a 0d 0a 20 20 20 20 20 20 56 44 55 28 22 31 38 |... VDU("18| 00000680 2c 30 2c 25 22 2c 20 31 2b 28 20 28 28 31 39 2a |,0,%", 1+( ((19*| 00000690 49 2b 31 32 29 2f 32 35 29 20 52 45 4d 20 33 29 |I+12)/25) REM 3)| 000006a0 20 29 0d 0a 0d 0a 20 20 20 20 20 20 2f 2f 20 44 | ).... // D| 000006b0 72 61 77 20 74 6f 20 6e 65 78 74 20 70 6f 69 6e |raw to next poin| 000006c0 74 20 77 68 6f 73 65 20 63 6f 6f 72 64 69 6e 61 |t whose coordina| 000006d0 74 65 73 20 61 72 65 20 33 2a 41 2a 53 49 4e 28 |tes are 3*A*SIN(| 000006e0 41 29 20 61 6e 64 0d 0a 20 20 20 20 20 20 2f 2f |A) and.. //| 000006f0 20 32 2a 41 2a 43 4f 53 28 41 29 2e 20 20 53 69 | 2*A*COS(A). Si| 00000700 6e 63 65 20 53 49 4e 28 41 29 20 61 6e 64 20 43 |nce SIN(A) and C| 00000710 4f 53 28 41 29 20 61 72 65 20 73 63 61 6c 65 64 |OS(A) are scaled| 00000720 20 62 79 20 31 30 30 30 30 20 75 73 65 0d 0a 20 | by 10000 use.. | 00000730 20 20 20 20 20 2f 2f 20 4d 55 4c 44 49 56 20 77 | // MULDIV w| 00000740 69 74 68 20 49 2f 35 20 69 6e 73 74 65 61 64 20 |ith I/5 instead | 00000750 6f 66 20 41 20 69 6e 20 74 68 65 20 6d 75 6c 74 |of A in the mult| 00000760 69 70 6c 69 63 61 74 69 6f 6e 2e 0d 0a 0d 0a 20 |iplication..... | 00000770 20 20 20 20 20 56 44 55 28 22 32 35 2c 35 2c 25 | VDU("25,5,%| 00000780 3b 25 3b 22 2c 20 4d 55 4c 44 49 56 28 53 49 4e |;%;", MULDIV(SIN| 00000790 28 41 29 2c 20 28 33 2a 49 2b 32 29 2f 35 2c 20 |(A), (3*I+2)/5, | 000007a0 31 30 30 30 30 29 2c 0d 0a 20 20 20 20 20 20 20 |10000),.. | 000007b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000007c0 4d 55 4c 44 49 56 28 43 4f 53 28 41 29 2c 20 28 |MULDIV(COS(A), (| 000007d0 32 2a 49 2b 32 29 2f 35 2c 20 31 30 30 30 30 29 |2*I+2)/5, 10000)| 000007e0 20 29 0d 0a 0d 0a 20 20 20 20 20 20 2f 2f 20 49 | ).... // I| 000007f0 6e 63 72 65 6d 65 6e 74 20 41 20 62 79 20 32 30 |ncrement A by 20| 00000800 30 30 20 28 72 65 70 72 65 73 65 6e 74 69 6e 67 |00 (representing| 00000810 20 30 2e 32 29 20 77 72 61 70 70 69 6e 67 20 72 | 0.2) wrapping r| 00000820 6f 75 6e 64 20 66 72 6f 6d 20 70 69 0d 0a 20 20 |ound from pi.. | 00000830 20 20 20 20 2f 2f 20 74 6f 20 2d 70 69 2e 0d 0a | // to -pi...| 00000840 0d 0a 20 20 20 20 20 20 54 45 53 54 20 41 20 3e |.. TEST A >| 00000850 20 50 49 2d 32 30 30 30 20 54 48 45 4e 0d 0a 20 | PI-2000 THEN.. | 00000860 20 20 20 20 20 20 20 20 41 20 3a 3d 20 41 2b 32 | A := A+2| 00000870 30 30 30 2d 28 32 2a 50 49 29 0d 0a 20 20 20 20 |000-(2*PI).. | 00000880 20 20 45 4c 53 45 0d 0a 20 20 20 20 20 20 20 20 | ELSE.. | 00000890 20 41 20 3a 3d 20 41 2b 32 30 30 30 0d 0a 0d 0a | A := A+2000....| 000008a0 20 20 20 20 20 20 2f 2f 20 43 68 61 6e 67 65 20 | // Change | 000008b0 74 68 65 20 70 61 6c 65 74 74 65 20 65 76 65 72 |the palette ever| 000008c0 79 20 34 74 68 20 70 6f 69 6e 74 2e 20 20 55 73 |y 4th point. Us| 000008d0 65 20 61 63 74 75 61 6c 20 63 6f 6c 6f 75 72 73 |e actual colours| 000008e0 20 33 2c 20 34 0d 0a 20 20 20 20 20 20 2f 2f 20 | 3, 4.. // | 000008f0 61 6e 64 20 35 20 28 79 65 6c 6c 6f 77 2c 20 62 |and 5 (yellow, b| 00000900 6c 75 65 20 61 6e 64 20 6d 61 67 65 6e 74 61 29 |lue and magenta)| 00000910 2e 0d 0a 0d 0a 20 20 20 20 20 20 49 46 20 28 49 |..... IF (I| 00000920 20 26 20 33 29 20 3d 20 30 20 44 4f 0d 0a 20 20 | & 3) = 0 DO.. | 00000930 20 20 20 20 24 28 20 46 4f 52 20 4a 20 3d 20 31 | $( FOR J = 1| 00000940 20 54 4f 20 33 0d 0a 20 20 20 20 20 20 20 20 20 | TO 3.. | 00000950 20 56 44 55 28 22 31 39 2c 25 2c 25 3b 25 3b 22 | VDU("19,%,%;%;"| 00000960 2c 20 4a 2c 20 28 28 43 2b 4a 29 20 52 45 4d 20 |, J, ((C+J) REM | 00000970 33 29 2b 33 2c 20 30 29 0d 0a 20 20 20 20 20 20 |3)+3, 0).. | 00000980 20 20 20 43 20 3a 3d 20 28 43 2b 31 29 20 52 45 | C := (C+1) RE| 00000990 4d 20 33 20 20 20 20 20 2f 2f 20 73 6f 20 6e 65 |M 3 // so ne| 000009a0 78 74 20 70 61 6c 65 74 74 65 20 63 68 61 6e 67 |xt palette chang| 000009b0 65 20 6d 6f 76 65 73 20 63 6f 6c 6f 75 72 73 20 |e moves colours | 000009c0 6f 6e 20 6f 6e 65 0d 0a 20 20 20 20 20 20 20 20 |on one.. | 000009d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000009e0 20 20 20 20 20 20 2f 2f 20 73 74 65 70 0d 0a 20 | // step.. | 000009f0 20 20 20 20 20 24 29 0d 0a 20 20 20 24 29 0d 0a | $).. $)..| 00000a00 0d 0a 20 20 20 2f 2f 20 57 61 69 74 20 66 6f 72 |.. // Wait for| 00000a10 20 35 20 73 65 63 6f 6e 64 73 20 74 68 65 6e 20 | 5 seconds then | 00000a20 67 6f 20 62 61 63 6b 20 74 6f 20 6d 6f 64 65 20 |go back to mode | 00000a30 37 2e 0d 0a 0d 0a 20 20 20 24 28 20 4c 45 54 20 |7..... $( LET | 00000a40 54 20 3d 20 54 49 4d 45 28 29 2b 35 30 30 0d 0a |T = TIME()+500..| 00000a50 20 20 20 20 20 20 49 46 20 54 20 3c 20 30 20 54 | IF T < 0 T| 00000a60 48 45 4e 20 54 20 3a 3d 20 54 2b 23 58 38 30 30 |HEN T := T+#X800| 00000a70 30 20 20 20 2f 2f 20 63 6f 6d 70 65 6e 73 61 74 |0 // compensat| 00000a80 65 20 66 6f 72 20 77 72 61 70 72 6f 75 6e 64 0d |e for wrapround.| 00000a90 0a 20 20 20 20 20 20 55 4e 54 49 4c 20 54 49 4d |. UNTIL TIM| 00000aa0 45 28 29 20 3d 20 54 20 4c 4f 4f 50 0d 0a 20 20 |E() = T LOOP.. | 00000ab0 20 20 20 20 4d 4f 44 45 28 37 29 0d 0a 20 20 20 | MODE(7).. | 00000ac0 24 29 0d 0a 24 29 0d 0a 0d 0a |$)..$)....| 00000aca