Skip to content

Commit 0cf7f71

Browse files
committed
ability to trace 2D frames
1 parent 38407e7 commit 0cf7f71

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

ext/Render.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,14 @@ function render(model, sol,
147147
if traces !== nothing
148148
tvec = range(sol.t[1], stop=sol.t[end], length=500)
149149
for frame in traces
150-
(frame.metadata !== nothing && get(frame.metadata, :frame, false)) || error("Only frames can be traced in animations.")
151-
points = get_trans(sol, frame, tvec) |> Matrix
150+
(frame.metadata !== nothing) || error("Only frames can be traced in animations.")
151+
if get(frame.metadata, :frame, false)
152+
points = get_trans(sol, frame, tvec) |> Matrix
153+
elseif get(frame.metadata, :frame_2d, false)
154+
points = get_trans_2d(sol, frame, tvec) |> Matrix
155+
else
156+
error("Got fishy frame metadata")
157+
end
152158
Makie.lines!(scene, points)
153159
end
154160
end
@@ -199,8 +205,14 @@ function render(model, sol, time::Real;
199205
if traces !== nothing
200206
tvec = range(sol.t[1], stop=sol.t[end], length=500)
201207
for frame in traces
202-
(frame.metadata !== nothing && get(frame.metadata, :frame, false)) || error("Only frames can be traced in animations.")
203-
points = get_trans(sol, frame, tvec) |> Matrix
208+
(frame.metadata !== nothing) || error("Only frames can be traced in animations.")
209+
if get(frame.metadata, :frame, false)
210+
points = get_trans(sol, frame, tvec) |> Matrix
211+
elseif get(frame.metadata, :frame_2d, false)
212+
points = get_trans_2d(sol, frame, tvec) |> Matrix
213+
else
214+
error("Got fishy frame metadata")
215+
end
204216
Makie.lines!(scene, points)
205217
end
206218
end
@@ -700,6 +712,9 @@ function get_frame_fun_2d(sol, frame)
700712
end
701713
end
702714

715+
get_trans_2d(sol, frame, t) = SVector{2}(sol(t, idxs = [frame.x, frame.y]))
716+
get_trans_2d(sol, frame, t::AbstractArray) = sol(t, idxs = [frame.x, frame.y])
717+
703718
function render!(scene, ::typeof(P.Body), sys, sol, t)
704719
sol(sol.t[1], idxs=sys.render)==true || return true # yes, == true
705720
color = get_color(sys, sol, :purple)

0 commit comments

Comments
 (0)