<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Sprühfarbe war ein schlechter Versuch des Schwarmverhaltens.Ich denke, der Teil, den ich vermisst habe, war die Ausrichtung, die http://gamedevelopment.tutsplus.com/tutorials/the-three-simple-rules-of-flocking-behaviors-alignment-cohesion-and-separat… lenkte mich hin.Hier ist ein neues Video.
ChanceOfDragons - YouTube

Und hier ist die JSL zum Erstellen der Bitmaps (nochmals keine Entschuldigung ... Sie müssen die Nachbarschafts- und Nahberechnung aus der Iterationsfunktion entfernen, wenn Sie mit den Schiebereglern spielen möchten.Dies ist die letzte JSL, die mehrere Stunden lief, um alle Bitmaps zu erstellen, nicht die frühe JSL, als ich versuchte, einige Parameterwerte zu finden, die interessante Ergebnisse liefern würden.)
// Ideen entlehnt von
// http://gamedevelopment.tutsplus.com/tutorials/the-three-simple-rules-of-flocking-behaviors-alignment-cohesion-and-separation--gamedev-3444
Nachbarschaft = 2; // Radius der Nachbarschaft
nnahe=20; // Anzahl der zu findenden Nachbarn in der Nachbarschaft
a = 0,04; b = 0,08; c = 0,2;
w = 0,8; // 1-w ist in die Mitte ziehen
speed=8;//kleiner ist schneller
x = 1;
y = 2;
dx = 3;
dy = 4;
Farbe=5;
nvar = 5;
nflock = 1700;
flock = J( nflock, nvar, . );
// Anfangspositionen von 10 bis 90 und Anfangsgeschwindigkeiten kleiner als 1 setzen
Parallele Zuweisung(
{x = x, y = y, dx = dx, dy = dy, nflock = nflock, Farbe=Farbe},
Herde[i, v] = If( v < dx,
100*(i+100)/(nflock+200),//Zufällige ganze Zahl( 10, 90 ),
if(v
)
);
Rahmen = 0;
iterieren = Funktion( {},
{temp = flock, iflock, irow, kdt = KDTable( flock[0, 1 :: 2] ), dxsum, dysum, xsum, ysum, myx, myy, xdif, ydif, Neighbor, nneighbors, len},
nnear = 10*(1.1+sin(frame/2000)); // ein bis zwanzig nächste Nachbarn
Nachbarschaft = 1*(1+cos(Frame/3000)); // null bis zwei nachbarschaft
{Zeilen, Abstand} = kdt << KNearestRows( {nnear, Neighborhood} );
Rahmen++;
Für (iflock = 1, iflock <= nflock, iflock++,
myx = temp[iflock, x];
myy = temp[iflock, y];
dxsumme = 0;
Dysum = 0; // Summe der Nachbargeschwindigkeiten
xsumme = 0;
ysum = 0; // Summe der Nachbarpositionen
xdif = 0;
ydif = 0; // Summe der Nachbarabstände
nNachbarn = 0;
For( irow = 1, irow <= nnear & (neighbor = rows[iflock, irow]) != 0, irow++,
nNachbarn++;
dxsum += temp[Nachbar, dx];
dysum += temp[Nachbar, dy];
wenn (1,
xsum += temp[Nachbar, x];
ysum += temp[Nachbar, y];
wenn (1,
xdif += (myx - temp[Nachbar, x]); // Vektor vom Nachbarn weg
ydif += (myy - temp[Nachbar, y]);
))
);
len = Sqrt( dxsum * dxsum + dysum * dysum );
Wenn ( len != 0,
dxsum /= Länge; // Dadurch wird die Geschwindigkeit in Richtung der Gruppe zu 1
dysum /= Länge;
,
dxsumme = 0;
Dysum = 0;
);
Wenn (Nachbarn,
xc = 50+40*sin((choose(1+mod(iflock,3),3,5,7)*frame)/2207);
yc = 50+40*cos((choose(1+mod(iflock,3),11,13,17)*frame)/3067);
xsum = ((1-w)*xc+(w*(xsum) / (nNachbarn))) - myx; // Dieser Vektor gibt die Richtung zum Gruppenzentrum an
ysum = ((1-w)*yc+(w*(ysum) / (nNachbarn))) - myy;
len = Sqrt( xsum * xsum + ysum * ysum );
if(len!=0,xsum/=len;ysum/=len,xsum=0;ysum=0);// auf 1 normalisiert
len = Sqrt( xdif * xdif + ydif * ydif );
if(len!=0,xdif/=len;ydif/=len,xdif=0;ydif=0); // auf 1 normalisiert
,
xsumme = 0;
ysum = 0;
xdif = 0;
ydif = 0;
);
herde[iflock, dx] += a*dxsumme + b*xsumme + c*xdif;
if(abs(flock[iflock,dx])>1, flock[iflock,dx]*=.9);
flock[iflock, x] += flock[iflock, dx]/speed;
if((flock[iflock, x] < -5 & flock[iflock, dx] < 0)|(flock[iflock, x] >105 & flock[iflock, dx] > 0), flock[iflock, dx] = - Herde[iflock, dx]);
herde[iflock, dy] += a*dysum + b*ysum + c*ydif;
if( abs(flock[iflock, dy])>1, flock[iflock, dy]*=.9);
flock[iflock, y] += flock[iflock, dy]/speed;
if((flock[iflock, y] < -5 & flock[iflock, dy] < 0)|(flock[iflock, y] >105 & flock[iflock, dy] > 0), flock[iflock, dy] = - Herde[iflock, dy]);
flock[iflock,color]=heatcolor((nneighbors)/(nnear),"spectral");//heatcolor((nneighbors-1)/(nnear+10),"jet");//3+nneighbors;/ /hlscolor(.4-.6*(nNachbarn)/(nnear),.5,1);//
);
);
iterieren ();
Neues Fenster ("Herde",
V Listenfeld (
gb = Diagrammfeld (
Unterdrücker,
Rahmengröße (1922, 1082),
<
Stiftgröße (3);
For( i = 1, i <= nflock, i++,
Stiftfarbe( flock[i, color] );
Line( {flock[i, x] - flock[i, dx], flock[i, y] - flock[i, dy]}, {flock[i, x], flock[i, y]} );
);
),
H Listenfeld (
Textfeld ("Ausrichtung"),
Schieberegler ( 0, .16, a ),
Textfeld ("Kohäsion"),
Schieberegler ( 0, .2, b ),
Textfeld ("Trennung"),
Schieberegler ( 0, .4, c ),
Textfeld ("Nachbarschaft"),
Slider Box( 0, 30, Nachbarschaft ),
,
Textfeld ("NNear"),
Slider Box( 1, 30, nnear ),
Textfeld ("Geschwindigkeit"),
Slider-Box (.5, 30, Geschwindigkeit)
)
)
);
Während (frame<=27000,
gb << inval;
gb << Aktualisierungsfenster;
Warte( 0 );
temp=gb[framebox(1)]<
Pixel=temp<
Pixel=Pixel[3::1082,3::1922];
temp<
temp<
iterieren ();
);