Refactor & improve

This commit is contained in:
Andras Schmelczer 2023-05-01 12:14:36 +01:00
parent b51cba28ad
commit b3d9229af5
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
22 changed files with 714 additions and 335 deletions

View file

@ -0,0 +1,29 @@
import { Agent } from '../pipelines/agents/agent';
import { settings } from '../settings';
import { Random } from '../utils/random';
import { vec2 } from 'gl-matrix';
export const spawnAgents = (canvasSize: vec2, agentCount: number): Array<Agent> => {
const minSize = Math.min(...canvasSize);
const ratio = Math.max(...canvasSize) / minSize;
const size = vec2.scale(vec2.create(), canvasSize, 1 / minSize);
vec2.normalize(size, size);
return new Array(agentCount).fill(0).map(() => {
const radius = Random.randomBetween(0, settings.startingRadius / ratio);
const angle = Random.randomBetween(0, Math.PI * 2);
const center = vec2.fromValues(0.5, 0.5);
const delta = vec2.fromValues(Math.cos(angle) * radius, Math.sin(angle) * radius);
vec2.divide(delta, delta, size);
const position = vec2.add(vec2.create(), center, delta);
return {
position,
angle: angle + Math.PI,
species: 0,
timeToLive: Random.randomBetween(10, 15000),
};
});
};