Home » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_15_03.adf » !AcornAns_AcornAns » Flocking/Basic/Old/Flock2

Flocking/Basic/Old/Flock2

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 » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_15_03.adf » !AcornAns_AcornAns
Filename: Flocking/Basic/Old/Flock2
Read OK:
File size: 0774 bytes
Load address: 0000
Exec address: 0000
File contents
   10REM Not flocking working
   20:
   30n%=16
   40G%=4
   50:
   60RC%=5*G%    :REM collision distance
   70RM%=8*G%    :REM velocity matching distance
   80RL%=40*G%   :REM local distance
   90:
  100RL2%=RL%*RL%
  110DIM x(n%-1), y(n%-1)
  120DIM xn(n%-1), yn(n%-1)
  130DIM vx(n%-1), vy(n%-1)
  140DIM dm(n%-1), im%(n%-1)
  150DIM ax(n%-1), ay(n%-1)
  160DIM avx(n%-1), avy(n%-1)
  170DIM ac%(n%-1)
  180:
  190MODE 18:OFF
  200ORIGIN 640,512
  210:
  220p%=125*G%
  230v%=G%*2
  240FOR i%=0 TO n%-1
  250 x(i%)=RND(p%)-p%/2
  260 y(i%)=RND(p%)-p%/2
  270 vx(i%)=RND(1)*v%
  280 vy(i%)=RND(1)*v%-v%/2
  290NEXT
  300:
  310REPEAT
  320 IF INKEY-99 RUN
  330 WAIT
  340 CLS
  350 FOR i%=0 TO n%-1
  360  PLOT 69,x(i%),y(i%)
  370 NEXT
  380 PROCmove
  390 FOR i%=0 TO n%-1
  400  x(i%)=xn(i%)
  410  y(i%)=yn(i%)
  420 NEXT
  430UNTIL 0
  440:
  450END
  460:
  470:
  480DEF PROCmove
  490:
  500FOR i%=0 TO n%-1
  510 dm(i%)=1E20
  520 ax(i%)=x(i%)
  530 ay(i%)=y(i%)
  540 avx(i%)=vx(i%)
  550 avy(i%)=vy(i%)
  560 ac%(i%)=1
  570NEXT
  580:
  590FOR i%=0 TO n%-2
  600 FOR j%=i%+1 TO n%-1
  610  d = (x(i%)-x(j%))*(x(i%)-x(j%)) + (y(i%)-y(j%))*(y(i%)-y(j%))
  620  IF d<dm(i%) dm(i%)=d:im%(i%)=j%
  630  IF d<dm(j%) dm(j%)=d:im%(j%)=i%
  640  IF d<RL2% THEN
  650   ax(i%)+=x(j%):ay(i%)+=y(j%):avx(i%)+=vx(j%):avy(i%)+=vy(j%):ac%(i%)+=1
  660   ax(j%)+=x(i%):ay(j%)+=y(i%):avx(j%)+=vx(i%):avy(j%)+=vy(i%):ac%(j%)+=1
  670  ENDIF
  680 NEXT
  690NEXT
  700:
  710FOR i%=0 TO n%-1
  720 IF dm(i%)>=RL2% THEN
  730  ax(i%)+=x(im%(i%)):ay(i%)+=y(im%(i%))
  740  avx(i%)+=vx(im%(i%)):avy(i%)+=vy(im%(i%))
  750  ac%(i%)+=1
  760 ENDIF
  770 d=SQRdm(i%):IF d<0.001 d=0.001
  780 IF d<RC% THEN
  790  u=(x(im%(i%))-x(i%))/d
  800  v=(y(im%(i%))-y(i%))/d
  810  vx=-u*G%
  820  vy=-v*G%
  830 ELSE
  840  IF d<RM% THEN
  850   vx=avx(i%)/ac%(i%)
  860   vy=avy(i%)/ac%(i%)
  870  ELSE
  880   ax(i%)=ax(i%)/ac%(i%)
  890   ay(i%)=ay(i%)/ac%(i%)
  900   dc=SQR( (ax(i%)-x(i%))*(ax(i%)-x(i%)) + (ay(i%)-y(i%))*(ay(i%)-y(i%)) ):IF dc<0.001 dc=0.001
  910   a=(ax(i%)-x(i%))/dc
  920   b=(ay(i%)-y(i%))/dc
  930   vx=a*G%*d/RM%
  940   vy=b*G%*d/RM%
  950  ENDIF
  960 ENDIF
  970 xn(i%)=x(i%)+vx
  980 yn(i%)=y(i%)+vy
  990 vx(i%)=vx
 1000 vy(i%)=vy
 1010NEXT
 1020:
 1030ENDPROC

� Not flocking working
:
	n%=16
(G%=4
2:
<%RC%=5*G%    :� collision distance
F-RM%=8*G%    :� velocity matching distance
P!RL%=40*G%   :� local distance
Z:
dRL2%=RL%*RL%
n� x(n%-1), y(n%-1)
x� xn(n%-1), yn(n%-1)
�� vx(n%-1), vy(n%-1)
�� dm(n%-1), im%(n%-1)
�� ax(n%-1), ay(n%-1)
�� avx(n%-1), avy(n%-1)
�� ac%(n%-1)
�:
�
� 18:�
�ȑ 640,512
�:
�
p%=125*G%
�v%=G%*2
�� i%=0 � n%-1
� x(i%)=�(p%)-p%/2
 y(i%)=�(p%)-p%/2
 vx(i%)=�(1)*v%
 vy(i%)=�(1)*v%-v%/2
"�
,:
6�
@
 � �-99 �
J Ȗ
T �
^ � i%=0 � n%-1
h  � 69,x(i%),y(i%)
r �
|
 �move
� � i%=0 � n%-1
�  x(i%)=xn(i%)
�  y(i%)=yn(i%)
� �
�� 0
�:
��
�:
�:
�� �move
�:
�� i%=0 � n%-1
� dm(i%)=1E20
 ax(i%)=x(i%)
 ay(i%)=y(i%)
 avx(i%)=vx(i%)
& avy(i%)=vy(i%)
0 ac%(i%)=1
:�
D:
N� i%=0 � n%-2
X � j%=i%+1 � n%-1
bC  d = (x(i%)-x(j%))*(x(i%)-x(j%)) + (y(i%)-y(j%))*(y(i%)-y(j%))
l$  � d<dm(i%) dm(i%)=d:im%(i%)=j%
v$  � d<dm(j%) dm(j%)=d:im%(j%)=i%
�  � d<RL2% �
�M   ax(i%)+=x(j%):ay(i%)+=y(j%):avx(i%)+=vx(j%):avy(i%)+=vy(j%):ac%(i%)+=1
�M   ax(j%)+=x(i%):ay(j%)+=y(i%):avx(j%)+=vx(i%):avy(j%)+=vy(i%):ac%(j%)+=1
�  �
� �
��
�:
�� i%=0 � n%-1
� � dm(i%)>=RL2% �
�+  ax(i%)+=x(im%(i%)):ay(i%)+=y(im%(i%))
�/  avx(i%)+=vx(im%(i%)):avy(i%)+=vy(im%(i%))
�  ac%(i%)+=1
� �
  d=�dm(i%):� d<0.001 d=0.001
 � d<RC% �
  u=(x(im%(i%))-x(i%))/d
   v=(y(im%(i%))-y(i%))/d
*  vx=-u*G%
4  vy=-v*G%
> �
H  � d<RM% �
R   vx=avx(i%)/ac%(i%)
\   vy=avy(i%)/ac%(i%)
f  �
p   ax(i%)=ax(i%)/ac%(i%)
z   ay(i%)=ay(i%)/ac%(i%)
�`   dc=�( (ax(i%)-x(i%))*(ax(i%)-x(i%)) + (ay(i%)-y(i%))*(ay(i%)-y(i%)) ):� dc<0.001 dc=0.001
�   a=(ax(i%)-x(i%))/dc
�   b=(ay(i%)-y(i%))/dc
�   vx=a*G%*d/RM%
�   vy=b*G%*d/RM%
�  �
� �
� xn(i%)=x(i%)+vx
� yn(i%)=y(i%)+vy
� vx(i%)=vx
� vy(i%)=vy
��
�:
�
�
00000000  0d 00 0a 1a f4 20 4e 6f  74 20 66 6c 6f 63 6b 69  |..... Not flocki|
00000010  6e 67 20 77 6f 72 6b 69  6e 67 0d 00 14 05 3a 0d  |ng working....:.|
00000020  00 1e 09 6e 25 3d 31 36  0d 00 28 08 47 25 3d 34  |...n%=16..(.G%=4|
00000030  0d 00 32 05 3a 0d 00 3c  25 52 43 25 3d 35 2a 47  |..2.:..<%RC%=5*G|
00000040  25 20 20 20 20 3a f4 20  63 6f 6c 6c 69 73 69 6f  |%    :. collisio|
00000050  6e 20 64 69 73 74 61 6e  63 65 0d 00 46 2d 52 4d  |n distance..F-RM|
00000060  25 3d 38 2a 47 25 20 20  20 20 3a f4 20 76 65 6c  |%=8*G%    :. vel|
00000070  6f 63 69 74 79 20 6d 61  74 63 68 69 6e 67 20 64  |ocity matching d|
00000080  69 73 74 61 6e 63 65 0d  00 50 21 52 4c 25 3d 34  |istance..P!RL%=4|
00000090  30 2a 47 25 20 20 20 3a  f4 20 6c 6f 63 61 6c 20  |0*G%   :. local |
000000a0  64 69 73 74 61 6e 63 65  0d 00 5a 05 3a 0d 00 64  |distance..Z.:..d|
000000b0  10 52 4c 32 25 3d 52 4c  25 2a 52 4c 25 0d 00 6e  |.RL2%=RL%*RL%..n|
000000c0  16 de 20 78 28 6e 25 2d  31 29 2c 20 79 28 6e 25  |.. x(n%-1), y(n%|
000000d0  2d 31 29 0d 00 78 18 de  20 78 6e 28 6e 25 2d 31  |-1)..x.. xn(n%-1|
000000e0  29 2c 20 79 6e 28 6e 25  2d 31 29 0d 00 82 18 de  |), yn(n%-1).....|
000000f0  20 76 78 28 6e 25 2d 31  29 2c 20 76 79 28 6e 25  | vx(n%-1), vy(n%|
00000100  2d 31 29 0d 00 8c 19 de  20 64 6d 28 6e 25 2d 31  |-1)..... dm(n%-1|
00000110  29 2c 20 69 6d 25 28 6e  25 2d 31 29 0d 00 96 18  |), im%(n%-1)....|
00000120  de 20 61 78 28 6e 25 2d  31 29 2c 20 61 79 28 6e  |. ax(n%-1), ay(n|
00000130  25 2d 31 29 0d 00 a0 1a  de 20 61 76 78 28 6e 25  |%-1)..... avx(n%|
00000140  2d 31 29 2c 20 61 76 79  28 6e 25 2d 31 29 0d 00  |-1), avy(n%-1)..|
00000150  aa 0f de 20 61 63 25 28  6e 25 2d 31 29 0d 00 b4  |... ac%(n%-1)...|
00000160  05 3a 0d 00 be 0a eb 20  31 38 3a 87 0d 00 c8 0e  |.:..... 18:.....|
00000170  c8 91 20 36 34 30 2c 35  31 32 0d 00 d2 05 3a 0d  |.. 640,512....:.|
00000180  00 dc 0d 70 25 3d 31 32  35 2a 47 25 0d 00 e6 0b  |...p%=125*G%....|
00000190  76 25 3d 47 25 2a 32 0d  00 f0 11 e3 20 69 25 3d  |v%=G%*2..... i%=|
000001a0  30 20 b8 20 6e 25 2d 31  0d 00 fa 15 20 78 28 69  |0 . n%-1.... x(i|
000001b0  25 29 3d b3 28 70 25 29  2d 70 25 2f 32 0d 01 04  |%)=.(p%)-p%/2...|
000001c0  15 20 79 28 69 25 29 3d  b3 28 70 25 29 2d 70 25  |. y(i%)=.(p%)-p%|
000001d0  2f 32 0d 01 0e 13 20 76  78 28 69 25 29 3d b3 28  |/2.... vx(i%)=.(|
000001e0  31 29 2a 76 25 0d 01 18  18 20 76 79 28 69 25 29  |1)*v%.... vy(i%)|
000001f0  3d b3 28 31 29 2a 76 25  2d 76 25 2f 32 0d 01 22  |=.(1)*v%-v%/2.."|
00000200  05 ed 0d 01 2c 05 3a 0d  01 36 05 f5 0d 01 40 0d  |....,.:..6....@.|
00000210  20 e7 20 a6 2d 39 39 20  f9 0d 01 4a 07 20 c8 96  | . .-99 ...J. ..|
00000220  0d 01 54 06 20 db 0d 01  5e 12 20 e3 20 69 25 3d  |..T. ...^. . i%=|
00000230  30 20 b8 20 6e 25 2d 31  0d 01 68 16 20 20 f0 20  |0 . n%-1..h.  . |
00000240  36 39 2c 78 28 69 25 29  2c 79 28 69 25 29 0d 01  |69,x(i%),y(i%)..|
00000250  72 06 20 ed 0d 01 7c 0a  20 f2 6d 6f 76 65 0d 01  |r. ...|. .move..|
00000260  86 12 20 e3 20 69 25 3d  30 20 b8 20 6e 25 2d 31  |.. . i%=0 . n%-1|
00000270  0d 01 90 12 20 20 78 28  69 25 29 3d 78 6e 28 69  |....  x(i%)=xn(i|
00000280  25 29 0d 01 9a 12 20 20  79 28 69 25 29 3d 79 6e  |%)....  y(i%)=yn|
00000290  28 69 25 29 0d 01 a4 06  20 ed 0d 01 ae 07 fd 20  |(i%).... ...... |
000002a0  30 0d 01 b8 05 3a 0d 01  c2 05 e0 0d 01 cc 05 3a  |0....:.........:|
000002b0  0d 01 d6 05 3a 0d 01 e0  0b dd 20 f2 6d 6f 76 65  |....:..... .move|
000002c0  0d 01 ea 05 3a 0d 01 f4  11 e3 20 69 25 3d 30 20  |....:..... i%=0 |
000002d0  b8 20 6e 25 2d 31 0d 01  fe 10 20 64 6d 28 69 25  |. n%-1.... dm(i%|
000002e0  29 3d 31 45 32 30 0d 02  08 11 20 61 78 28 69 25  |)=1E20.... ax(i%|
000002f0  29 3d 78 28 69 25 29 0d  02 12 11 20 61 79 28 69  |)=x(i%).... ay(i|
00000300  25 29 3d 79 28 69 25 29  0d 02 1c 13 20 61 76 78  |%)=y(i%).... avx|
00000310  28 69 25 29 3d 76 78 28  69 25 29 0d 02 26 13 20  |(i%)=vx(i%)..&. |
00000320  61 76 79 28 69 25 29 3d  76 79 28 69 25 29 0d 02  |avy(i%)=vy(i%)..|
00000330  30 0e 20 61 63 25 28 69  25 29 3d 31 0d 02 3a 05  |0. ac%(i%)=1..:.|
00000340  ed 0d 02 44 05 3a 0d 02  4e 11 e3 20 69 25 3d 30  |...D.:..N.. i%=0|
00000350  20 b8 20 6e 25 2d 32 0d  02 58 15 20 e3 20 6a 25  | . n%-2..X. . j%|
00000360  3d 69 25 2b 31 20 b8 20  6e 25 2d 31 0d 02 62 43  |=i%+1 . n%-1..bC|
00000370  20 20 64 20 3d 20 28 78  28 69 25 29 2d 78 28 6a  |  d = (x(i%)-x(j|
00000380  25 29 29 2a 28 78 28 69  25 29 2d 78 28 6a 25 29  |%))*(x(i%)-x(j%)|
00000390  29 20 2b 20 28 79 28 69  25 29 2d 79 28 6a 25 29  |) + (y(i%)-y(j%)|
000003a0  29 2a 28 79 28 69 25 29  2d 79 28 6a 25 29 29 0d  |)*(y(i%)-y(j%)).|
000003b0  02 6c 24 20 20 e7 20 64  3c 64 6d 28 69 25 29 20  |.l$  . d<dm(i%) |
000003c0  64 6d 28 69 25 29 3d 64  3a 69 6d 25 28 69 25 29  |dm(i%)=d:im%(i%)|
000003d0  3d 6a 25 0d 02 76 24 20  20 e7 20 64 3c 64 6d 28  |=j%..v$  . d<dm(|
000003e0  6a 25 29 20 64 6d 28 6a  25 29 3d 64 3a 69 6d 25  |j%) dm(j%)=d:im%|
000003f0  28 6a 25 29 3d 69 25 0d  02 80 10 20 20 e7 20 64  |(j%)=i%....  . d|
00000400  3c 52 4c 32 25 20 8c 0d  02 8a 4d 20 20 20 61 78  |<RL2% ....M   ax|
00000410  28 69 25 29 2b 3d 78 28  6a 25 29 3a 61 79 28 69  |(i%)+=x(j%):ay(i|
00000420  25 29 2b 3d 79 28 6a 25  29 3a 61 76 78 28 69 25  |%)+=y(j%):avx(i%|
00000430  29 2b 3d 76 78 28 6a 25  29 3a 61 76 79 28 69 25  |)+=vx(j%):avy(i%|
00000440  29 2b 3d 76 79 28 6a 25  29 3a 61 63 25 28 69 25  |)+=vy(j%):ac%(i%|
00000450  29 2b 3d 31 0d 02 94 4d  20 20 20 61 78 28 6a 25  |)+=1...M   ax(j%|
00000460  29 2b 3d 78 28 69 25 29  3a 61 79 28 6a 25 29 2b  |)+=x(i%):ay(j%)+|
00000470  3d 79 28 69 25 29 3a 61  76 78 28 6a 25 29 2b 3d  |=y(i%):avx(j%)+=|
00000480  76 78 28 69 25 29 3a 61  76 79 28 6a 25 29 2b 3d  |vx(i%):avy(j%)+=|
00000490  76 79 28 69 25 29 3a 61  63 25 28 6a 25 29 2b 3d  |vy(i%):ac%(j%)+=|
000004a0  31 0d 02 9e 07 20 20 cd  0d 02 a8 06 20 ed 0d 02  |1....  ..... ...|
000004b0  b2 05 ed 0d 02 bc 05 3a  0d 02 c6 11 e3 20 69 25  |.......:..... i%|
000004c0  3d 30 20 b8 20 6e 25 2d  31 0d 02 d0 15 20 e7 20  |=0 . n%-1.... . |
000004d0  64 6d 28 69 25 29 3e 3d  52 4c 32 25 20 8c 0d 02  |dm(i%)>=RL2% ...|
000004e0  da 2b 20 20 61 78 28 69  25 29 2b 3d 78 28 69 6d  |.+  ax(i%)+=x(im|
000004f0  25 28 69 25 29 29 3a 61  79 28 69 25 29 2b 3d 79  |%(i%)):ay(i%)+=y|
00000500  28 69 6d 25 28 69 25 29  29 0d 02 e4 2f 20 20 61  |(im%(i%)).../  a|
00000510  76 78 28 69 25 29 2b 3d  76 78 28 69 6d 25 28 69  |vx(i%)+=vx(im%(i|
00000520  25 29 29 3a 61 76 79 28  69 25 29 2b 3d 76 79 28  |%)):avy(i%)+=vy(|
00000530  69 6d 25 28 69 25 29 29  0d 02 ee 10 20 20 61 63  |im%(i%))....  ac|
00000540  25 28 69 25 29 2b 3d 31  0d 02 f8 06 20 cd 0d 03  |%(i%)+=1.... ...|
00000550  02 20 20 64 3d b6 64 6d  28 69 25 29 3a e7 20 64  |.  d=.dm(i%):. d|
00000560  3c 30 2e 30 30 31 20 64  3d 30 2e 30 30 31 0d 03  |<0.001 d=0.001..|
00000570  0c 0e 20 e7 20 64 3c 52  43 25 20 8c 0d 03 16 1c  |.. . d<RC% .....|
00000580  20 20 75 3d 28 78 28 69  6d 25 28 69 25 29 29 2d  |  u=(x(im%(i%))-|
00000590  78 28 69 25 29 29 2f 64  0d 03 20 1c 20 20 76 3d  |x(i%))/d.. .  v=|
000005a0  28 79 28 69 6d 25 28 69  25 29 29 2d 79 28 69 25  |(y(im%(i%))-y(i%|
000005b0  29 29 2f 64 0d 03 2a 0e  20 20 76 78 3d 2d 75 2a  |))/d..*.  vx=-u*|
000005c0  47 25 0d 03 34 0e 20 20  76 79 3d 2d 76 2a 47 25  |G%..4.  vy=-v*G%|
000005d0  0d 03 3e 06 20 cc 0d 03  48 0f 20 20 e7 20 64 3c  |..>. ...H.  . d<|
000005e0  52 4d 25 20 8c 0d 03 52  19 20 20 20 76 78 3d 61  |RM% ...R.   vx=a|
000005f0  76 78 28 69 25 29 2f 61  63 25 28 69 25 29 0d 03  |vx(i%)/ac%(i%)..|
00000600  5c 19 20 20 20 76 79 3d  61 76 79 28 69 25 29 2f  |\.   vy=avy(i%)/|
00000610  61 63 25 28 69 25 29 0d  03 66 07 20 20 cc 0d 03  |ac%(i%)..f.  ...|
00000620  70 1c 20 20 20 61 78 28  69 25 29 3d 61 78 28 69  |p.   ax(i%)=ax(i|
00000630  25 29 2f 61 63 25 28 69  25 29 0d 03 7a 1c 20 20  |%)/ac%(i%)..z.  |
00000640  20 61 79 28 69 25 29 3d  61 79 28 69 25 29 2f 61  | ay(i%)=ay(i%)/a|
00000650  63 25 28 69 25 29 0d 03  84 60 20 20 20 64 63 3d  |c%(i%)...`   dc=|
00000660  b6 28 20 28 61 78 28 69  25 29 2d 78 28 69 25 29  |.( (ax(i%)-x(i%)|
00000670  29 2a 28 61 78 28 69 25  29 2d 78 28 69 25 29 29  |)*(ax(i%)-x(i%))|
00000680  20 2b 20 28 61 79 28 69  25 29 2d 79 28 69 25 29  | + (ay(i%)-y(i%)|
00000690  29 2a 28 61 79 28 69 25  29 2d 79 28 69 25 29 29  |)*(ay(i%)-y(i%))|
000006a0  20 29 3a e7 20 64 63 3c  30 2e 30 30 31 20 64 63  | ):. dc<0.001 dc|
000006b0  3d 30 2e 30 30 31 0d 03  8e 1a 20 20 20 61 3d 28  |=0.001....   a=(|
000006c0  61 78 28 69 25 29 2d 78  28 69 25 29 29 2f 64 63  |ax(i%)-x(i%))/dc|
000006d0  0d 03 98 1a 20 20 20 62  3d 28 61 79 28 69 25 29  |....   b=(ay(i%)|
000006e0  2d 79 28 69 25 29 29 2f  64 63 0d 03 a2 14 20 20  |-y(i%))/dc....  |
000006f0  20 76 78 3d 61 2a 47 25  2a 64 2f 52 4d 25 0d 03  | vx=a*G%*d/RM%..|
00000700  ac 14 20 20 20 76 79 3d  62 2a 47 25 2a 64 2f 52  |..   vy=b*G%*d/R|
00000710  4d 25 0d 03 b6 07 20 20  cd 0d 03 c0 06 20 cd 0d  |M%....  ..... ..|
00000720  03 ca 14 20 78 6e 28 69  25 29 3d 78 28 69 25 29  |... xn(i%)=x(i%)|
00000730  2b 76 78 0d 03 d4 14 20  79 6e 28 69 25 29 3d 79  |+vx.... yn(i%)=y|
00000740  28 69 25 29 2b 76 79 0d  03 de 0e 20 76 78 28 69  |(i%)+vy.... vx(i|
00000750  25 29 3d 76 78 0d 03 e8  0e 20 76 79 28 69 25 29  |%)=vx.... vy(i%)|
00000760  3d 76 79 0d 03 f2 05 ed  0d 03 fc 05 3a 0d 04 06  |=vy.........:...|
00000770  05 e1 0d ff                                       |....|
00000774