-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_snapshots.jl
65 lines (48 loc) · 1.54 KB
/
plot_snapshots.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using PyPlot
function plot_snapshots()
time_header_regex = r"time = ([-+]?[0-9]\.?[0-9]*)"
t = NaN
t::Float64
frameno = 0
frameno::Int64
framedir = tempdir() * "/frames/"
mkpath(framedir)
println("storing frames in $framedir")
configuration = Array{Float64,1}()
configuration::Array{Float64,1}
function plot_configuration(time, frameno, config)
fig = figure()
plot(config[:,1], config[:,2], ".")
axis( [-10, 10, -10, 10] )
xlabel("x")
ylabel("y")
title("evolution for t=$time")
filename = framedir * lpad(frameno,5,0)
savefig(filename)
close(fig)
end
time_header_regex = r"time = ([-+]?[0-9]\.?[0-9]*)"
#particle_regex = r"([-+]?[0-9]\.?[0-9]*) ([-+]?[0-9]\.?[0-9]*)"
for line in eachline(STDIN)
if ismatch(time_header_regex, line)
if 0 < length(configuration)
nparticles = Int(length(configuration)/2)
reshaped = reshape( configuration, nparticles, 2);
plot_configuration( t, frameno, reshaped )
configuration = Array{Float64,1}()
end
m = match(time_header_regex, line)
t = parse(Float64, m[1])
frameno = frameno + 1
continue
end
pos_str_arr = split(line)
#m = match(particle_regex, line)
xpos = parse(Float64, pos_str_arr[1])
ypos = parse(Float64, pos_str_arr[2])
push!(configuration, xpos)
push!(configuration, ypos)
end
run(`ffmpeg -framerate 30 -i $framedir%05d.png -c:v libx264 -r 30 -tune animation -pix_fmt yuv420p out.mp4`)
end
plot_snapshots()