Published
Edited
May 23, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
vis = {
// simulation
const sim = new AA.Simulation({
width: 550,
height: 550,
gridStep: 10,
beforeTick: () => {
for (let ac of sim.actors) ac.state.neighbor = false;
},
// these help performance a little:
updateMassesAndRadii: false,
  updatePointings: false,
  updateSquareStates: false,
  updateZoneStates: false,
  applySteeringForces: false
}).vis({baseColor: 0xffffff});
invalidation.then(() => sim.end());

// still actors
sim.populate({
n: Math.round(29 * nCircles / 30),
random: true,
overlap: true,
radius: 1.5,
setup: ac => ac.vis({tint: ac => ac.state.neighbor ? 0x0 : 0xaaaaaa})
});

// moving actors
sim.populate({
n: Math.round(nCircles / 30),
random: true,
radius: 3,
setup: ac => {
ac.wrap = true;
ac.vel = new AA.Vector(2, 2)
ac.state.moving = true;
ac.updateState = function() {
const neighbors = test === 'neighbors'
? this.neighbors(10, 'actor')
: this.nearest(10, null, 'actor');
for (let neighbor of neighbors || []) {
neighbor.state.neighbor = true;
}
};
ac.vis({tint: AV.colors.blue});
}
});

return AV.visObs(sim, {
stats: true,
backParticles: true,
// these help performance a little:
updateRadii: false,
updatePointings: false
});
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more