You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,8 @@ Flocking simulation of starling murmuration using web graphics library (webGL) a
3
3
4
4
> **Checkout the [demo](https://techcentaur.github.io/Starling-Simulation/index.html#64) here**
5
5
6
+

7
+
6
8
#### Flocking behavior
7
9
Flocking is a the motion of birds together and flocking behavior is a type of behavior exhibited when a group of birds, called a flock, are in flight.
8
10
@@ -127,12 +129,52 @@ guiControls = new function(){
127
129
spotLight =newTHREE.SpotLight(0xffffff);
128
130
scene.add(spotLight);
129
131
```
132
+
133
+
### Algorithm of Separation, Cohesion, and Alignment.
134
+
135
+
**Separation**
136
+
- `distSquared` is the square of distance between the current position of canvas texture rendered ( at that time ) and each point on resolution window ( for boids ).
137
+
- We shall add a velocity vector away from the velocity.now, with change proportional to the rendering time ( del_change ) and the amount any boid is closer to some other boid on the old texture.
138
+
- `zoneRadiusSquared` is a design choice, we set its value to 35.0 ( a hit and trial technique ).
139
+
140
+
```javascript
141
+
percent = distSquared / zoneRadiusSquared;
142
+
if ( percent < separationThresh ) {
143
+
f = (separationThresh / percent -1.0) * del_change;
144
+
velocity -=normalize(dir) * f;
145
+
}
146
+
```
147
+
148
+
**Alignment**
149
+
150
+
- We deal with alignment by creating a reference direction and then adjusting it using trignometric function with change proportional to the rendering time.
- It allows you to execute code on the next available screen repaint, taking the guess work out of **getting in sync** with the user's browser and hardware readiness to make changes to the screen.
133
174
134
175
- Code running inside background tabs in your browser are either paused or slowed down significantly (to 2 frames per second or less) automatically to further **save user system resources**.
135
176
177
+
136
178
## Folder-Terminology
137
179
138
180
- **js-libs**: Static javascript library files from three.js and some from webGL-js.
0 commit comments