|
|
@ -23,7 +23,7 @@ function Particle(parent, bounds, globalGrid, observables) { |
|
|
|
vision: createVisionGrid(this.config) |
|
|
|
vision: createVisionGrid(this.config) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
this.id = Random.id(6); |
|
|
|
this.id = Random.id(12); |
|
|
|
|
|
|
|
|
|
|
|
this.nodes = { |
|
|
|
this.nodes = { |
|
|
|
body: createBodyNode(this.config), |
|
|
|
body: createBodyNode(this.config), |
|
|
@ -45,7 +45,11 @@ function Particle(parent, bounds, globalGrid, observables) { |
|
|
|
this.arc = Arc.create(bounds, this.grids.global); |
|
|
|
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.grids.global.setPoint({ |
|
|
|
|
|
|
|
x: this.arc.endX, |
|
|
|
|
|
|
|
y: this.arc.endY, |
|
|
|
|
|
|
|
type: ENTITIES.PARTICLE |
|
|
|
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
|
|
this.remove$ = new Rx.Subject(); |
|
|
|
this.remove$ = new Rx.Subject(); |
|
|
|
|
|
|
|
|
|
|
@ -73,7 +77,11 @@ function Particle(parent, bounds, globalGrid, observables) { |
|
|
|
// ===== PROTOTYPE =====
|
|
|
|
// ===== PROTOTYPE =====
|
|
|
|
|
|
|
|
|
|
|
|
Particle.prototype.remove = function() { |
|
|
|
Particle.prototype.remove = function() { |
|
|
|
// this.grids.globals.deletePoint({ x: p.arc.endX, y: p.arc.endY, type: ENTITIES.PARTICLE });
|
|
|
|
this.grids.global.deletePoint({ |
|
|
|
|
|
|
|
x: this.arc.endX, |
|
|
|
|
|
|
|
y: this.arc.endY, |
|
|
|
|
|
|
|
type: ENTITIES.PARTICLE |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const parent = this.nodes.container.parentNode; |
|
|
|
const parent = this.nodes.container.parentNode; |
|
|
|
parent.removeChild(this.nodes.container); |
|
|
|
parent.removeChild(this.nodes.container); |
|
|
@ -82,16 +90,23 @@ Particle.prototype.remove = function() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Particle.prototype.subscribeNextFrame = function() { |
|
|
|
Particle.prototype.subscribeNextFrame = function() { |
|
|
|
// this.arc = Arc.goto(this.arc, 200, 200, this.config.speed)
|
|
|
|
this.grids.global.deletePoint({ |
|
|
|
|
|
|
|
x: this.arc.endX, |
|
|
|
|
|
|
|
y: this.arc.endY, |
|
|
|
|
|
|
|
type: ENTITIES.PARTICLE |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (this.nodes === undefined) { |
|
|
|
if (this.nodes === undefined) { |
|
|
|
console.warn('no nodes in', this.id); |
|
|
|
console.warn('no nodes in', this.id); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.arc = Arc.goto(this.arc, 200, 200, this.config.speed)
|
|
|
|
|
|
|
|
|
|
|
|
this.arc = Arc.step(this.arc, this.config.bounds, this.config.speed); |
|
|
|
this.arc = Arc.step(this.arc, this.config.bounds, this.config.speed); |
|
|
|
|
|
|
|
|
|
|
|
if (this.leader !== null) { |
|
|
|
if (this.leader !== null) { |
|
|
|
// this.arc = Arc.follow(this.arc, this.leader.arc);
|
|
|
|
this.arc = Arc.follow(this.arc, this.leader.arc); |
|
|
|
} else if (this.arc.length <= 0 && this.config.randomize) { |
|
|
|
} else if (this.arc.length <= 0 && this.config.randomize) { |
|
|
|
this.arc = Arc.randomize(this.arc); |
|
|
|
this.arc = Arc.randomize(this.arc); |
|
|
|
} |
|
|
|
} |
|
|
@ -100,16 +115,16 @@ Particle.prototype.subscribeNextFrame = function() { |
|
|
|
const { hazards, particles } = look(this.arc, this.grids); |
|
|
|
const { hazards, particles } = look(this.arc, this.grids); |
|
|
|
|
|
|
|
|
|
|
|
if (hazards.length > 0) { |
|
|
|
if (hazards.length > 0) { |
|
|
|
this.arc = Arc.evade(this.arc); |
|
|
|
// this.arc = Arc.evade(this.arc);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// this.updateLeader(particles);
|
|
|
|
this.updateLeader(particles); |
|
|
|
|
|
|
|
|
|
|
|
// const prevX = p.arc.endX;
|
|
|
|
|
|
|
|
// const prevY = p.arc.endY;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.grid.deletePoint({ x: prevX, y: prevY, type: ENTITIES.PARTICLE });
|
|
|
|
this.grids.global.setPoint({ |
|
|
|
// this.grid.setPoint({ x: p.arc.endX, y: p.arc.endY, type: ENTITIES.PARTICLE }, p);
|
|
|
|
x: this.arc.endX, |
|
|
|
|
|
|
|
y: this.arc.endY, |
|
|
|
|
|
|
|
type: ENTITIES.PARTICLE |
|
|
|
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
|
|
repaintContainer(this.nodes.container, this.arc); |
|
|
|
repaintContainer(this.nodes.container, this.arc); |
|
|
|
repaintBody(this.nodes.body, this.arc, this.isLeader); |
|
|
|
repaintBody(this.nodes.body, this.arc, this.isLeader); |
|
|
|