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() { function Animation3a() {
this.options = { this.options = {
cohesion: true, cohesion: true,
count: 2, count: 10,
maxCount: 5, maxCount: 1000,
showVisionGrid: true, showVisionGrid: true,
speed: 4 speed: 4
}; };
@ -31,12 +31,15 @@ function Animation3a() {
this.updateCount(this.options.count); this.updateCount(this.options.count);
// TODO extract Arc // 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 X dimension modified by core UI, maybe recalc grid in animation start?
// TODO remove bottom padding from Disqus // TODO remove bottom padding from Disqus
// TODO ANIM2ab randomize hazards // TODO ANIM2ab randomize hazards
// TODO fix "hangup" small radius evade bug // TODO fix "hangup" small radius evade bug
// TODO ANIM3a perf Scale vision grid to 1000 particles // TODO ANIM3a perf Scale vision grid to 1000 particles
// TODO ANIM3a circular leadership
// TODO hazard grid, particles grid // TODO hazard grid, particles grid
// TODO completely seal Particle // 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 = { const random = {
bool: (weight) => Math.random() < (weight || 0.5), bool: (weight) => Math.random() < (weight || 0.5),
color: () => `rgb( color: () => `rgb(
${Math.floor(Math.random() * 170)}, ${Math.floor(Math.random() * 230)},
${Math.floor(Math.random() * 170)}, ${Math.floor(Math.random() * 230)},
${Math.floor(Math.random() * 170)} ${Math.floor(Math.random() * 230)}
)`, )`,
id: () => String.fromCharCode( id: () => String.fromCharCode(
random.num(65, 90), 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) // random.num(97, 122), random.num(97, 122), random.num(97, 122)
), ),
num: (min, max) => min + Math.round(Math.random() * (max - min)), num: (min, max) => min + Math.round(Math.random() * (max - min)),
} }
@ -24,12 +24,12 @@ function Particle(parent, bounds, config, globalGrid) {
behavior: BEHAVIOR.COHESION, behavior: BEHAVIOR.COHESION,
bounds, bounds,
color: random.color(), color: random.color(),
gridSize: 10, gridSize: 5,
randomize: true, randomize: true,
showMovementCircle: false, showMovementCircle: false,
showVisionGrid: false, showVisionGrid: false,
speed: 4, speed: 4,
visionRadius: 200 visionRadius: 50
}, config) }, config)
}); });
@ -99,14 +99,15 @@ Particle.prototype.nextFrame = function(globalGrid) {
if (leader !== undefined) { if (leader !== undefined) {
leader.isLeader = true; 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.isLeader = false;
this.leader = leader; this.leader = leader;
} }
} }
this.updateLeader();
// if (hazards.length) { // if (hazards.length) {
// this.arc = evade(this.arc, this.grids.vision); // 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 ===== // ===== CREATION =====
function createArc(bounds, grids) { function createArc(bounds, grids) {
@ -199,7 +217,7 @@ function createContainerNode(config, id) {
function createVisionGrid(config) { function createVisionGrid(config) {
const { gridSize: side, visionRadius: radius } = config; const { gridSize: side, visionRadius: radius } = config;
const r0 = radius; const r0 = radius;
const r1 = 20; const r1 = 30;
const points = []; const points = [];
@ -324,11 +342,11 @@ function followArc(arc, arcToFollow) {
arc = reverseArc(arc); arc = reverseArc(arc);
} }
// if (Math.abs(arc.theta - arcToFollow.theta) > 0.1) { if (Math.abs(arc.theta - arcToFollow.theta) > 0.1) {
// arc = moveArc(arc, 20); arc = moveArc(arc, 20);
// } else { } else {
// arc = moveArc(arc, arcToFollow.radius); arc = moveArc(arc, arcToFollow.radius);
// } }
return arc; return arc;
} }

Loading…
Cancel
Save