| Posted: 02:37pm 06 Jun 2026 |
|
|
|
Dot murmuration simulation on the screen
MODE 2 Const NumBoids=30 Dim X(NumBoids), Y(NumBoids) Dim VX(NumBoids), VY(NumBoids)
For i=1 To NumBoids X(i)=Int(Rnd*MM.HRES) Y(i)=Int(Rnd*MM.VRES) VX(i)=(Rnd*4)-2 VY(i)=(Rnd*4)-2 Next
Do For i=1 To NumBoids Pixel X(i),Y(i),0 'Clear centerX=0: centerY=0 avoidX=0: avoidY=0 alignX=0: alignY=0 count=0 For j=1 To NumBoids If i<>j Then distX=X(j)-X(i) distY=Y(j)-Y(i) dist=Sqr(distX*distX+distY*distY) If dist<100 And dist>0 Then centerX=centerX+X(j) centerY=centerY+Y(j) alignX=alignX+VX(j) alignY=alignY+VY(j) count=count+1 If dist<20 Then avoidX=avoidX-distX avoidY=avoidY-distY EndIf EndIf EndIf Next j If count>0 Then centerX=(centerX/count)-X(i) centerY=(centerY/count)-Y(i) VX(i)=VX(i)+centerX*.005 VY(i)=VY(i)+centerY*.005 alignX=alignX/count alignY=alignY/count VX(i)=VX(i)+alignX*.05 VY(i)=VY(i)+alignY*.05 EndIf VX(i)=VX(i)+avoidX*.1 VY(i)=VY(i)+avoidY*.1 speed=Sqr(VX(i)*VX(i)+VY(i)*VY(i)) If speed>4 Then VX(i)=(VX(i)/speed)*4 VY(i)=(VY(i)/speed)*4 EndIf X(i)=X(i)+VX(i) Y(i)=Y(i)+VY(i) If X(i)<10 Then VX(i)=VX(i)+.5 If X(i)> MM.HRES-10 Then VX(i)=VX(i)-.5 If Y(i)<10 Then VY(i)=VY(i)+.5 If Y(i)>MM.VRES-10 Then VY(i)=VY(i)-.5 Pixel X(i),Y(i) Next i Loop While Inkey$="" |