Skip to content

Commit

Permalink
Enable settings for neurons
Browse files Browse the repository at this point in the history
  • Loading branch information
dragly committed Sep 30, 2024
1 parent 04bacc4 commit 0f6ca67
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions neuronify-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ fn yellow() -> Vec3 {
srgb(223, 142, 29)
}
fn neurocolor(neuron_type: &NeuronType, value: f32) -> Vec3 {
let v = 1.0 / (1.0 + (-4.9 * (-1.0 + 2.0 * value)).exp());
let v = 1.0 / (1.0 + (-5.0 * (value - 0.5)).exp());
match *neuron_type {
NeuronType::Excitatory => v * base() + (1.0 - v) * blue(),
NeuronType::Inhibitory => v * mantle() + (1.0 - v) * red(),
Expand Down Expand Up @@ -1317,8 +1317,10 @@ impl visula::Simulation for Neuronify {
let neuron_spheres: Vec<Sphere> = world
.query::<(&Neuron, &NeuronDynamics, &Position, &NeuronType)>()
.iter()
.map(|(_entity, (_neuron, dynamics, position, neuron_type))| {
let value = ((dynamics.voltage + 100.0) / 150.0).clamp(0.0, 1.0) as f32;
.map(|(_entity, (neuron, dynamics, position, neuron_type))| {
let value = ((dynamics.voltage - neuron.resting_potential)
/ (neuron.threshold - neuron.resting_potential))
.clamp(0.0, 1.0) as f32;
Sphere {
position: position.position,
color: neurocolor(neuron_type, value),
Expand Down Expand Up @@ -1537,6 +1539,41 @@ impl visula::Simulation for Neuronify {
});
});
}
if let Ok(mut neuron) = self.world.get::<&mut Neuron>(active_entity) {
ui.collapsing("Neuron", |ui| {
egui::Grid::new("neuron_settings").show(ui, |ui| {
ui.label("Threshold:");
ui.add(egui::Slider::new(&mut neuron.threshold, -10.0..=100.0));
ui.end_row();

ui.label("Resting potential:");
ui.add(egui::Slider::new(
&mut neuron.resting_potential,
-120.0..=-40.0,
));
ui.end_row();
});
});
}
if let Ok(dynamics) = self.world.get::<&NeuronDynamics>(active_entity) {
ui.collapsing("Dynamics", |ui| {
egui::Grid::new("neuron_dynamics").show(ui, |ui| {
ui.label("Voltage:");
ui.label(format!("{:.2} mV", dynamics.voltage));
ui.end_row();
});
});
}
if let Ok(mut leak_current) = self.world.get::<&mut LeakCurrent>(active_entity)
{
ui.collapsing("Leak current", |ui| {
egui::Grid::new("neuron_settings").show(ui, |ui| {
ui.label("Tau:");
ui.add(egui::Slider::new(&mut leak_current.tau, 0.01..=10.0));
ui.end_row();
});
});
}
});
}
}
Expand Down

0 comments on commit 0f6ca67

Please sign in to comment.