Update app.py
Browse files
app.py
CHANGED
|
@@ -134,55 +134,31 @@ class Environment:
|
|
| 134 |
def visualize(self):
|
| 135 |
fig = make_subplots(rows=1, cols=2, subplot_titles=("Cell Distribution", "Population Over Time"))
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
population_counts[cell_type].append(count)
|
| 161 |
-
|
| 162 |
-
for cell_type, counts in population_counts.items():
|
| 163 |
-
fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type), row=1, col=2)
|
| 164 |
-
|
| 165 |
-
fig.update_xaxes(title_text="Time", row=1, col=2)
|
| 166 |
-
fig.update_yaxes(title_text="Population", row=1, col=2)
|
| 167 |
-
|
| 168 |
-
fig.update_layout(height=600, width=1200,
|
| 169 |
-
title_text=f"Cell Evolution Simulation (Time: {self.time})")
|
| 170 |
-
return fig
|
| 171 |
-
|
| 172 |
-
def run_simulation(num_steps, initial_cells):
|
| 173 |
-
env = Environment(100, 100)
|
| 174 |
-
|
| 175 |
-
# Add initial cells
|
| 176 |
-
for _ in range(initial_cells):
|
| 177 |
-
cell = Cell(random.uniform(0, env.width), random.uniform(0, env.height))
|
| 178 |
-
env.add_cell(cell)
|
| 179 |
-
|
| 180 |
-
# Run simulation
|
| 181 |
-
for step in range(num_steps):
|
| 182 |
-
env.update()
|
| 183 |
-
if step % 10 == 0: # Visualize every 10 steps
|
| 184 |
-
yield env.visualize()
|
| 185 |
|
|
|
|
| 186 |
st.title("Cell Evolution Simulation")
|
| 187 |
|
| 188 |
num_steps = st.slider("Number of simulation steps", 100, 1000, 500)
|
|
|
|
| 134 |
def visualize(self):
|
| 135 |
fig = make_subplots(rows=1, cols=2, subplot_titles=("Cell Distribution", "Population Over Time"))
|
| 136 |
|
| 137 |
+
def setup_figure(env):
|
| 138 |
+
fig = make_subplots(rows=1, cols=2, subplot_titles=("Cell Distribution", "Population Over Time"))
|
| 139 |
+
|
| 140 |
+
# Cell distribution
|
| 141 |
+
for cell_type, data in env.get_visualization_data()[0].items():
|
| 142 |
+
fig.add_trace(go.Scatter(
|
| 143 |
+
x=data["x"], y=data["y"], mode='markers',
|
| 144 |
+
marker=dict(color=data["color"], size=data["size"]),
|
| 145 |
+
name=cell_type
|
| 146 |
+
), row=1, col=1)
|
| 147 |
+
|
| 148 |
+
# Population over time
|
| 149 |
+
for cell_type, counts in env.population_history.items():
|
| 150 |
+
fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type), row=1, col=2)
|
| 151 |
+
|
| 152 |
+
fig.update_xaxes(title_text="X", row=1, col=1)
|
| 153 |
+
fig.update_yaxes(title_text="Y", row=1, col=1)
|
| 154 |
+
fig.update_xaxes(title_text="Time", row=1, col=2)
|
| 155 |
+
fig.update_yaxes(title_text="Population", row=1, col=2)
|
| 156 |
+
|
| 157 |
+
fig.update_layout(height=600, width=1200, title_text="Cell Evolution Simulation")
|
| 158 |
+
|
| 159 |
+
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
+
# Streamlit app
|
| 162 |
st.title("Cell Evolution Simulation")
|
| 163 |
|
| 164 |
num_steps = st.slider("Number of simulation steps", 100, 1000, 500)
|