create value boxes by method, fix heatmap size bug, remove dt from step method

feat/diff_Jaguar
Nikola Sebastian Munder 2025-06-09 11:52:59 +02:00
parent 6bc2c3f06d
commit 34da199ff2
1 changed files with 30 additions and 14 deletions

View File

@ -1,5 +1,6 @@
using GLMakie, Observables
using .AnimalFurFHN
include("../src/constants.jl")
using .Constants
# Parameters and initial conditions
@ -8,11 +9,11 @@ dx = 1.0
Du, Dv = Observable(0.16), Observable(0.08)
F, k = Observable(0.060), Observable(0.062)
dt = 1.0
params_obs = Observable(AnimalFurFHN.GSParams(N, dx, 0.16, 0.08, 0.08, 0.06))
params_obs = Observable(GSParams(N, dx, 0.16, 0.08, 0.08, 0.06))
function update_params!(params_obs, u, v, feed, kill)
old = params_obs[]
params_obs[] = AnimalFurFHN.GSParams(old.N, old.dx, u, v, feed, kill)
params_obs[] = GSParams(old.N, old.dx, u, v, feed, kill)
end
lift(Du, Dv, F, k) do u, v, F, k
@ -46,8 +47,8 @@ function step!(U, V)
v = V[2:end-1, 2:end-1]
uvv = u .* v .* v
u_new = u .+ (Du[] .* lap_u .- uvv .+ F[] .* (1 .- u)) .* dt
v_new = v .+ (Dv[] .* lap_v .+ uvv .- (F[] .+ k[]) .* v) .* dt
u_new = u .+ (Du[] .* lap_u .- uvv .+ F[] .* (1 .- u))
v_new = v .+ (Dv[] .* lap_v .+ uvv .- (F[] .+ k[]) .* v)
# Update with new values
U[2:end-1, 2:end-1] .= u_new
@ -65,21 +66,22 @@ function step!(U, V)
V[:, end] .= V[:, 2]
# Update heatmap observable
heat_obs[] = copy(U)
return U
end
function multi_step!(state, n_steps)
for _ in 1:n_steps
step!(state[1], state[2])
heat_obs[] = step!(state[1], state[2])
end
end
# Build GUI
fig = Figure(size=(600, 600))
ax = Axis(fig[1, 1])
gh = GridLayout(fig[1, 1])
ax = Axis(gh[1, 1])
hm = Makie.heatmap!(ax, heat_obs, colormap=:magma)
hm = Makie.heatmap!(ax, heat_obs, colormap=:viridis)
ax.aspect = DataAspect()
# # Controls
@ -90,12 +92,26 @@ btn_start = Button(buttongrid[1, 2], label="Start")
btn_stop = Button(buttongrid[1, 3], label="Stop")
btn_reset = Button(buttongrid[1, 4], label="Reset")
gh[1, 2] = textboxgrid = GridLayout(tellwidth=false)
rowsize!(gh, 1, Relative(1.0))
function param_box!(row, labeltxt, observable)
Label(textboxgrid[row, 1], labeltxt)
box = Textbox(textboxgrid[row, 2], validator=Float64, width=50, placeholder=labeltxt, stored_string="$(observable[])")
on(box.stored_string) do s
try
observable[] = parse(Float64, s)
println("changed $labeltxt to $s")
catch
@warn "Invalid input for $labeltxt: $s"
end
end
end
param_box!(1, "Du", Du)
param_box!(2, "Dv", Dv)
param_box!(3, "Feed", F)
param_box!(4, "kill", k)
fig[3, 1] = textboxgrid = GridLayout(tellwidth=false)
box_u = Textbox(textboxgrid[1, 1], validator=Float64, placeholder="word")
# box_v = Textbox(textboxgrid[1, 2], validator=Float64, placeholder="word")
# box_feed = Textbox(textboxgrid[1, 3], validator=Float64, placeholder="word")
# box_kill = Textbox(textboxgrid[1, 4], validator=Float64, placeholder="word")
# Timer and state for animation
running = Observable(false)
function reset!(U, V, heat_obs)