From 5140a2f32c426c6dfe0d336286a4dd37d8b2520a Mon Sep 17 00:00:00 2001 From: Niki Laptop <2212719@stud.hs-mannheim.de> Date: Tue, 10 Jun 2025 13:30:19 +0200 Subject: [PATCH] add feature that you can drop disbalanced concentration at click point, to kickstart reaction there --- scripts/run_simulation.jl | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/scripts/run_simulation.jl b/scripts/run_simulation.jl index 84e01c2..99c13a4 100644 --- a/scripts/run_simulation.jl +++ b/scripts/run_simulation.jl @@ -94,14 +94,41 @@ ax.aspect = DataAspect() spoint = select_point(ax.scene) +function coord_to_index(x, y, N) + ix = clamp(round(Int, x), 1, N) + iy = clamp(round(Int, y), 1, N) + return ix, iy +end +r = 5 + +on(spoint) do pt + if pt === nothing + return + end + x, y = pt + i, j = coord_to_index(x, y, N) + + # get corners of square that will get filled with concentration + imin = max(i - r, 1) + imax = min(i + r, N) + jmin = max(j - r, 1) + jmax = min(j + r, N) + + # set disbalanced concentration of U and V + U[imin:imax, jmin:jmax] .= 0.5 + V[imin:imax, jmin:jmax] .= 0.25 + + heat_obs[] = copy(U) +end + # # Controls run_label = Observable("Run") -fig[2, 1] = buttongrid = GridLayout(tellwidth=false) -btn_step = Button(buttongrid[1, 1], label="Step") +fig[2, 1] = buttongrid = GridLayout(ax.scene, tellwidth=false) +btn_step = Button(buttongrid[1, 1], width=50, label="Step") btn_start = Button(buttongrid[1, 2], width=50, label=run_label) -btn_reset = Button(buttongrid[1, 3], label="Reset") +btn_reset = Button(buttongrid[1, 3], width=50, label="Reset") -gh[1, 2] = textboxgrid = GridLayout(tellwidth=false) +gh[1, 2] = textboxgrid = GridLayout(ax.scene, tellwidth=false) rowsize!(gh, 1, Relative(1.0)) function param_box!(row, labeltxt, observable) Label(textboxgrid[row, 1], labeltxt) @@ -148,7 +175,7 @@ end on(btn_start.clicks) do _ @async while running[] - multi_step!((U, V), 30) + multi_step!((U, V), 60) sleep(0.05) # ~20 FPS end end