|
|
|
@ -39,6 +39,12 @@ function Particle(parent, bounds, globalGrid, observables) { |
|
|
|
|
this.isLeader = false; |
|
|
|
|
|
|
|
|
|
this.arc = Arc.create(bounds, this.grids.global); |
|
|
|
|
|
|
|
|
|
// If starting in a hazard, recurse.
|
|
|
|
|
while (this.grids.global.getPoint({ x: this.arc.endX, y: this.arc.endY, type: ENTITIES.HAZARD}) !== undefined) { |
|
|
|
|
this.arc = Arc.create(bounds, this.grids.global); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// this.grids.global.setPoint({ x: p.arc.endX, y: p.arc.endY, type: ENTITIES.PARTICLE }, p); // USE ID?
|
|
|
|
|
|
|
|
|
|
this.remove$ = new Rx.Subject(); |
|
|
|
@ -51,12 +57,17 @@ function Particle(parent, bounds, globalGrid, observables) { |
|
|
|
|
.takeUntil(this.remove$) |
|
|
|
|
.subscribe(this.subscribeSpeed.bind(this)); |
|
|
|
|
|
|
|
|
|
observables.randomize$ && observables.randomize$ |
|
|
|
|
.takeUntil(this.remove$) |
|
|
|
|
.subscribe(this.subscribeRandomize.bind(this)); |
|
|
|
|
|
|
|
|
|
observables.circle$ && observables.circle$ |
|
|
|
|
.takeUntil(this.remove$) |
|
|
|
|
.subscribe(this.subscribeCircle.bind(this)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// observables.randomize$.subscribe(this.subscribeRandomize.bind(this));
|
|
|
|
|
observables.vision$ && observables.vision$ |
|
|
|
|
.takeUntil(this.remove$) |
|
|
|
|
.subscribe(this.subscribeVision.bind(this)); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// ===== PROTOTYPE =====
|
|
|
|
@ -85,12 +96,12 @@ Particle.prototype.subscribeNextFrame = function() { |
|
|
|
|
this.arc = Arc.randomize(this.arc); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// this.grids.vision = updateVisionGrid(this.arc, this.config, this.grids);
|
|
|
|
|
// const { hazards, particles } = look(this.arc, this.grids);
|
|
|
|
|
this.grids.vision = updateVisionGrid(this.arc, this.config, this.grids); |
|
|
|
|
const { hazards, particles } = look(this.arc, this.grids); |
|
|
|
|
|
|
|
|
|
// if (hazards.length > 0) {
|
|
|
|
|
// this.arc = Arc.evade(this.arc);
|
|
|
|
|
// }
|
|
|
|
|
if (hazards.length > 0) { |
|
|
|
|
this.arc = Arc.evade(this.arc); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// this.updateLeader(particles);
|
|
|
|
|
|
|
|
|
@ -110,13 +121,6 @@ Particle.prototype.subscribeSpeed = function(value) { |
|
|
|
|
this.config.speed = value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if (showVision === true && this.nodes.visionGrid === undefined) {
|
|
|
|
|
// this.nodes.visionGrid = createVisionGridNodes(this.config, this.grids, this.nodes);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (showVision === false && this.nodes.visionGrid !== undefined) {
|
|
|
|
|
// delete this.nodex.visionGrid;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Particle.prototype.subscribeCircle = function(show) { |
|
|
|
|
if (show === false) { |
|
|
|
@ -132,6 +136,15 @@ Particle.prototype.subscribeRandomize = function(value) { |
|
|
|
|
this.config.randomize = value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Particle.prototype.subscribeVision = function(show) { |
|
|
|
|
if (show === false) { |
|
|
|
|
this.nodes.visionGrid.forEach(n => n.parentNode.removeChild(n)); |
|
|
|
|
delete this.nodes.visionGrid; |
|
|
|
|
} else { |
|
|
|
|
this.nodes.visionGrid = createVisionGridNodes(this.config, this.grids, this.nodes); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Particle.prototype.updateLeader = function(particles) { |
|
|
|
|
if (this.config.behavior !== BEHAVIOR.COHESION) { |
|
|
|
|
return; |
|
|
|
@ -249,10 +262,6 @@ function createVisionGrid(config) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function createVisionGridNodes(config, grids, nodes) { |
|
|
|
|
if (config.showVision === false) { |
|
|
|
|
return undefined; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return grids.vision.reduce((acc, { x, y }) => { |
|
|
|
|
const div = document.createElement('div'); |
|
|
|
|
div.className = 'particle-vision-dot'; |
|
|
|
|