Home » Archimedes archive » Acorn User » AU 1998-03 A.adf » Features » DiffDim3/Program1
DiffDim3/Program1
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 » Archimedes archive » Acorn User » AU 1998-03 A.adf » Features |
Filename: | DiffDim3/Program1 |
Read OK: | ✔ |
File size: | 04D1 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
10REM Program 1 20REM 30REM Demonstrate the shading function 40: 50REM Switch to 16 colour screen mode and set greyscale palette 60DIM p% 52 70P%=p% 80[OPT 0 90mov r0,#0 100swi &2006D 110bvs P%+28 120tst r0,#1 130beq P%+20 140swi 256+22 150swi &20100+20 160movvc r0,#2 170movvc pc,r14 180swi 256+22 190swi 256+9 200mov r0,#4 210mov pc,r14 220] 230y_step%=USR(p%):OFF 240FORn%=0 TO 15:COLOUR n%,n%<<4,n%<<4,n%<<4:NEXT 250: 260REM Setup dither array to improve colour range 270DIM dither(1) 280dither()=0.75,0.25 290: 300REM Sphere loop 310REPEAT 320: 330REM Get random unit light direction (facing viewer) 340REPEAT 350lx=RND(1)*2-1:ly=RND(1)*2-1:lz=1-lx*lx-lz*lz 360UNTIL lz>0 370lz=SQR(lz) 380: 390REM Plot random sized sphere 400PROCsphere(RND(1280),RND(1024),RND(256)) 410UNTIL FALSE 420: 430DEFPROCsphere(cx%,cy%,radius%) 440radsqu%=radius%*radius% 450FORy%=-radius% TO radius% STEP y_step% 460xl%=SQR(radsqu%-y%*y%) 470ys%=y%*y% 480FORx%=-xl% TO xl% STEP 2 490: 500REM Calculate surface normal 510z=SQR(radsqu%-x%*x%-ys%) 520d=1/SQR(x%*x%+ys%+z*z) 530nx=x%*d:ny=y%*d:nz=z*d 540: 550REM Caculate light intensity 560c=15*(lx*nx+ly*ny+lz*nz) 570: 580REM Dither light intensity and clamp 590IF c>0 c+=dither(((x% AND 2) EOR ((y% AND 4)>>1))>>1) ELSE c=0 600IF c>15 c=15 610: 620REM Plot pixel 630GCOL c 640POINT x%+cx%,y%+cy% 650NEXT 660NEXT 670ENDPROC
� Program 1 � &� Demonstrate the shading function (: 2?� Switch to 16 colour screen mode and set greyscale palette <� p% 52 F P%=p% P [OPT 0 Z mov r0,#0 dswi &2006D n bvs P%+28 x tst r0,#1 � beq P%+20 �swi 256+22 �swi &20100+20 �movvc r0,#2 �movvc pc,r14 �swi 256+22 � swi 256+9 � mov r0,#4 �mov pc,r14 �] �y_step%=�(p%):� �'�n%=0 � 15:� n%,n%<<4,n%<<4,n%<<4:� �: 0� Setup dither array to improve colour range � dither(1) dither()=0.75,0.25 ": ,� Sphere loop 6� @: J5� Get random unit light direction (facing viewer) T� ^,lx=�(1)*2-1:ly=�(1)*2-1:lz=1-lx*lx-lz*lz h � lz>0 rlz=�(lz) |: �� Plot random sized sphere �#�sphere(�(1280),�(1024),�(256)) �� � �: ���sphere(cx%,cy%,radius%) �radsqu%=radius%*radius% �$�y%=-radius% � radius% � y_step% �xl%=�(radsqu%-y%*y%) � ys%=y%*y% ��x%=-xl% � xl% � 2 �: �� Calculate surface normal �z=�(radsqu%-x%*x%-ys%) d=1/�(x%*x%+ys%+z*z) nx=x%*d:ny=y%*d:nz=z*d : &� Caculate light intensity 0c=15*(lx*nx+ly*ny+lz*nz) :: D&� Dither light intensity and clamp N8� c>0 c+=dither(((x% � 2) � ((y% � 4)>>1))>>1) � c=0 X� c>15 c=15 b: l� Plot pixel v� c �Ȓ x%+cx%,y%+cy% �� �� �� �
00000000 0d 00 0a 0f f4 20 50 72 6f 67 72 61 6d 20 31 0d |..... Program 1.| 00000010 00 14 05 f4 0d 00 1e 26 f4 20 44 65 6d 6f 6e 73 |.......&. Demons| 00000020 74 72 61 74 65 20 74 68 65 20 73 68 61 64 69 6e |trate the shadin| 00000030 67 20 66 75 6e 63 74 69 6f 6e 0d 00 28 05 3a 0d |g function..(.:.| 00000040 00 32 3f f4 20 53 77 69 74 63 68 20 74 6f 20 31 |.2?. Switch to 1| 00000050 36 20 63 6f 6c 6f 75 72 20 73 63 72 65 65 6e 20 |6 colour screen | 00000060 6d 6f 64 65 20 61 6e 64 20 73 65 74 20 67 72 65 |mode and set gre| 00000070 79 73 63 61 6c 65 20 70 61 6c 65 74 74 65 0d 00 |yscale palette..| 00000080 3c 0b de 20 70 25 20 35 32 0d 00 46 09 50 25 3d |<.. p% 52..F.P%=| 00000090 70 25 0d 00 50 0a 5b 4f 50 54 20 30 0d 00 5a 0d |p%..P.[OPT 0..Z.| 000000a0 6d 6f 76 20 72 30 2c 23 30 0d 00 64 0e 73 77 69 |mov r0,#0..d.swi| 000000b0 20 26 32 30 30 36 44 0d 00 6e 0d 62 76 73 20 50 | &2006D..n.bvs P| 000000c0 25 2b 32 38 0d 00 78 0d 74 73 74 20 72 30 2c 23 |%+28..x.tst r0,#| 000000d0 31 0d 00 82 0d 62 65 71 20 50 25 2b 32 30 0d 00 |1....beq P%+20..| 000000e0 8c 0e 73 77 69 20 32 35 36 2b 32 32 0d 00 96 11 |..swi 256+22....| 000000f0 73 77 69 20 26 32 30 31 30 30 2b 32 30 0d 00 a0 |swi &20100+20...| 00000100 0f 6d 6f 76 76 63 20 72 30 2c 23 32 0d 00 aa 10 |.movvc r0,#2....| 00000110 6d 6f 76 76 63 20 70 63 2c 72 31 34 0d 00 b4 0e |movvc pc,r14....| 00000120 73 77 69 20 32 35 36 2b 32 32 0d 00 be 0d 73 77 |swi 256+22....sw| 00000130 69 20 32 35 36 2b 39 0d 00 c8 0d 6d 6f 76 20 72 |i 256+9....mov r| 00000140 30 2c 23 34 0d 00 d2 0e 6d 6f 76 20 70 63 2c 72 |0,#4....mov pc,r| 00000150 31 34 0d 00 dc 05 5d 0d 00 e6 13 79 5f 73 74 65 |14....]....y_ste| 00000160 70 25 3d ba 28 70 25 29 3a 87 0d 00 f0 27 e3 6e |p%=.(p%):....'.n| 00000170 25 3d 30 20 b8 20 31 35 3a fb 20 6e 25 2c 6e 25 |%=0 . 15:. n%,n%| 00000180 3c 3c 34 2c 6e 25 3c 3c 34 2c 6e 25 3c 3c 34 3a |<<4,n%<<4,n%<<4:| 00000190 ed 0d 00 fa 05 3a 0d 01 04 30 f4 20 53 65 74 75 |.....:...0. Setu| 000001a0 70 20 64 69 74 68 65 72 20 61 72 72 61 79 20 74 |p dither array t| 000001b0 6f 20 69 6d 70 72 6f 76 65 20 63 6f 6c 6f 75 72 |o improve colour| 000001c0 20 72 61 6e 67 65 0d 01 0e 0f de 20 64 69 74 68 | range..... dith| 000001d0 65 72 28 31 29 0d 01 18 16 64 69 74 68 65 72 28 |er(1)....dither(| 000001e0 29 3d 30 2e 37 35 2c 30 2e 32 35 0d 01 22 05 3a |)=0.75,0.25..".:| 000001f0 0d 01 2c 11 f4 20 53 70 68 65 72 65 20 6c 6f 6f |..,.. Sphere loo| 00000200 70 0d 01 36 05 f5 0d 01 40 05 3a 0d 01 4a 35 f4 |p..6....@.:..J5.| 00000210 20 47 65 74 20 72 61 6e 64 6f 6d 20 75 6e 69 74 | Get random unit| 00000220 20 6c 69 67 68 74 20 64 69 72 65 63 74 69 6f 6e | light direction| 00000230 20 28 66 61 63 69 6e 67 20 76 69 65 77 65 72 29 | (facing viewer)| 00000240 0d 01 54 05 f5 0d 01 5e 2c 6c 78 3d b3 28 31 29 |..T....^,lx=.(1)| 00000250 2a 32 2d 31 3a 6c 79 3d b3 28 31 29 2a 32 2d 31 |*2-1:ly=.(1)*2-1| 00000260 3a 6c 7a 3d 31 2d 6c 78 2a 6c 78 2d 6c 7a 2a 6c |:lz=1-lx*lx-lz*l| 00000270 7a 0d 01 68 0a fd 20 6c 7a 3e 30 0d 01 72 0c 6c |z..h.. lz>0..r.l| 00000280 7a 3d b6 28 6c 7a 29 0d 01 7c 05 3a 0d 01 86 1e |z=.(lz)..|.:....| 00000290 f4 20 50 6c 6f 74 20 72 61 6e 64 6f 6d 20 73 69 |. Plot random si| 000002a0 7a 65 64 20 73 70 68 65 72 65 0d 01 90 23 f2 73 |zed sphere...#.s| 000002b0 70 68 65 72 65 28 b3 28 31 32 38 30 29 2c b3 28 |phere(.(1280),.(| 000002c0 31 30 32 34 29 2c b3 28 32 35 36 29 29 0d 01 9a |1024),.(256))...| 000002d0 07 fd 20 a3 0d 01 a4 05 3a 0d 01 ae 1d dd f2 73 |.. .....:......s| 000002e0 70 68 65 72 65 28 63 78 25 2c 63 79 25 2c 72 61 |phere(cx%,cy%,ra| 000002f0 64 69 75 73 25 29 0d 01 b8 1b 72 61 64 73 71 75 |dius%)....radsqu| 00000300 25 3d 72 61 64 69 75 73 25 2a 72 61 64 69 75 73 |%=radius%*radius| 00000310 25 0d 01 c2 24 e3 79 25 3d 2d 72 61 64 69 75 73 |%...$.y%=-radius| 00000320 25 20 b8 20 72 61 64 69 75 73 25 20 88 20 79 5f |% . radius% . y_| 00000330 73 74 65 70 25 0d 01 cc 18 78 6c 25 3d b6 28 72 |step%....xl%=.(r| 00000340 61 64 73 71 75 25 2d 79 25 2a 79 25 29 0d 01 d6 |adsqu%-y%*y%)...| 00000350 0d 79 73 25 3d 79 25 2a 79 25 0d 01 e0 16 e3 78 |.ys%=y%*y%.....x| 00000360 25 3d 2d 78 6c 25 20 b8 20 78 6c 25 20 88 20 32 |%=-xl% . xl% . 2| 00000370 0d 01 ea 05 3a 0d 01 f4 1e f4 20 43 61 6c 63 75 |....:..... Calcu| 00000380 6c 61 74 65 20 73 75 72 66 61 63 65 20 6e 6f 72 |late surface nor| 00000390 6d 61 6c 0d 01 fe 1a 7a 3d b6 28 72 61 64 73 71 |mal....z=.(radsq| 000003a0 75 25 2d 78 25 2a 78 25 2d 79 73 25 29 0d 02 08 |u%-x%*x%-ys%)...| 000003b0 18 64 3d 31 2f b6 28 78 25 2a 78 25 2b 79 73 25 |.d=1/.(x%*x%+ys%| 000003c0 2b 7a 2a 7a 29 0d 02 12 1a 6e 78 3d 78 25 2a 64 |+z*z)....nx=x%*d| 000003d0 3a 6e 79 3d 79 25 2a 64 3a 6e 7a 3d 7a 2a 64 0d |:ny=y%*d:nz=z*d.| 000003e0 02 1c 05 3a 0d 02 26 1e f4 20 43 61 63 75 6c 61 |...:..&.. Cacula| 000003f0 74 65 20 6c 69 67 68 74 20 69 6e 74 65 6e 73 69 |te light intensi| 00000400 74 79 0d 02 30 1c 63 3d 31 35 2a 28 6c 78 2a 6e |ty..0.c=15*(lx*n| 00000410 78 2b 6c 79 2a 6e 79 2b 6c 7a 2a 6e 7a 29 0d 02 |x+ly*ny+lz*nz)..| 00000420 3a 05 3a 0d 02 44 26 f4 20 44 69 74 68 65 72 20 |:.:..D&. Dither | 00000430 6c 69 67 68 74 20 69 6e 74 65 6e 73 69 74 79 20 |light intensity | 00000440 61 6e 64 20 63 6c 61 6d 70 0d 02 4e 38 e7 20 63 |and clamp..N8. c| 00000450 3e 30 20 63 2b 3d 64 69 74 68 65 72 28 28 28 78 |>0 c+=dither(((x| 00000460 25 20 80 20 32 29 20 82 20 28 28 79 25 20 80 20 |% . 2) . ((y% . | 00000470 34 29 3e 3e 31 29 29 3e 3e 31 29 20 8b 20 63 3d |4)>>1))>>1) . c=| 00000480 30 0d 02 58 0f e7 20 63 3e 31 35 20 63 3d 31 35 |0..X.. c>15 c=15| 00000490 0d 02 62 05 3a 0d 02 6c 10 f4 20 50 6c 6f 74 20 |..b.:..l.. Plot | 000004a0 70 69 78 65 6c 0d 02 76 07 e6 20 63 0d 02 80 14 |pixel..v.. c....| 000004b0 c8 92 20 78 25 2b 63 78 25 2c 79 25 2b 63 79 25 |.. x%+cx%,y%+cy%| 000004c0 0d 02 8a 05 ed 0d 02 94 05 ed 0d 02 9e 05 e1 0d |................| 000004d0 ff |.| 000004d1