Cohesion starting to cohere.

master
Ben Burlingham 8 years ago
parent ce06797630
commit 9c4145f8b7
  1. 7
      js/animation3a.js
  2. 4
      js/bundle.js
  3. 48
      js/particle.js

@ -8,8 +8,8 @@ import { CONTROLS, ENTITIES } from './enums';
function Animation3a() {
this.options = {
cohesion: true,
count: 2,
maxCount: 5,
count: 10,
maxCount: 1000,
showVisionGrid: true,
speed: 4
};
@ -31,12 +31,15 @@ function Animation3a() {
this.updateCount(this.options.count);
// TODO extract Arc
// TODO get "top" leader, once...don't update each time?
// TODO if leader sees follower, assign to this leader?
// TODO X dimension modified by core UI, maybe recalc grid in animation start?
// TODO remove bottom padding from Disqus
// TODO ANIM2ab randomize hazards
// TODO fix "hangup" small radius evade bug
// TODO ANIM3a perf Scale vision grid to 1000 particles
// TODO ANIM3a circular leadership
// TODO hazard grid, particles grid
// TODO completely seal Particle

File diff suppressed because one or more lines are too long

@ -5,13 +5,13 @@ import Store from './store';
const random = {
bool: (weight) => Math.random() < (weight || 0.5),
color: () => `rgb(
${Math.floor(Math.random() * 170)},
${Math.floor(Math.random() * 170)},
${Math.floor(Math.random() * 170)}
${Math.floor(Math.random() * 230)},
${Math.floor(Math.random() * 230)},
${Math.floor(Math.random() * 230)}
)`,
id: () => String.fromCharCode(
random.num(65, 90), random.num(97, 122), random.num(97, 122),
random.num(97, 122), random.num(97, 122), random.num(97, 122)
random.num(65, 90), random.num(97, 122), random.num(97, 122)
// random.num(97, 122), random.num(97, 122), random.num(97, 122)
),
num: (min, max) => min + Math.round(Math.random() * (max - min)),
}
@ -24,12 +24,12 @@ function Particle(parent, bounds, config, globalGrid) {
behavior: BEHAVIOR.COHESION,
bounds,
color: random.color(),
gridSize: 10,
gridSize: 5,
randomize: true,
showMovementCircle: false,
showVisionGrid: false,
speed: 4,
visionRadius: 200
visionRadius: 50
}, config)
});
@ -99,14 +99,15 @@ Particle.prototype.nextFrame = function(globalGrid) {
if (leader !== undefined) {
leader.isLeader = true;
console.warn(`${particles[0].id} is now a leader`);
console.log(`${this.id} is now following ${leader.id}`);
// console.log(`${this.id} is now following ${leader.id}`);
this.isLeader = false;
this.leader = leader;
}
}
this.updateLeader();
// if (hazards.length) {
// this.arc = evade(this.arc, this.grids.vision);
// }
@ -141,6 +142,23 @@ Particle.prototype.updateConfig = function(config) {
}
}
Particle.prototype.updateLeader = function() {
if (this.leader === null) {
return;
}
while (this.leader.leader !== null) {
this.leader.isLeader = false;
this.leader = this.leader.leader;
// console.error(this.id, 'is now following', this.leader.id)
}
// Prevents circular leadership, where a leader sees its tail.
if (this.leader.id === this.id) {
this.leader = null;
}
}
// ===== CREATION =====
function createArc(bounds, grids) {
@ -199,7 +217,7 @@ function createContainerNode(config, id) {
function createVisionGrid(config) {
const { gridSize: side, visionRadius: radius } = config;
const r0 = radius;
const r1 = 20;
const r1 = 30;
const points = [];
@ -324,11 +342,11 @@ function followArc(arc, arcToFollow) {
arc = reverseArc(arc);
}
// if (Math.abs(arc.theta - arcToFollow.theta) > 0.1) {
// arc = moveArc(arc, 20);
// } else {
// arc = moveArc(arc, arcToFollow.radius);
// }
if (Math.abs(arc.theta - arcToFollow.theta) > 0.1) {
arc = moveArc(arc, 20);
} else {
arc = moveArc(arc, arcToFollow.radius);
}
return arc;
}

Loading…
Cancel
Save