From 2c884ab5ab63a3b4a57e490bc5b2c1f9c73c95fe Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 16 Oct 2015 12:03:40 -0400 Subject: [PATCH] animations --- src/Plots.jl | 5 +++++ src/animation.jl | 23 +++++++++++++++++++++++ src/args.jl | 4 ++-- src/plot.jl | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/animation.jl diff --git a/src/Plots.jl b/src/Plots.jl index 680c63e9..4db151a5 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -83,6 +83,10 @@ export supportedMarkers, subplotSupported, + Animation, + frame, + gif, + # recipes PlotRecipe, EllipseRecipe, @@ -105,6 +109,7 @@ include("args.jl") include("plot.jl") include("subplot.jl") include("recipes.jl") +include("animation.jl") # --------------------------------------------------------- diff --git a/src/animation.jl b/src/animation.jl new file mode 100644 index 00000000..dce6a64d --- /dev/null +++ b/src/animation.jl @@ -0,0 +1,23 @@ + +immutable Animation{P<:PlottingObject} + plt::P + dir::ASCIIString + frames::Vector{ASCIIString} +end + +function Animation(plt::PlottingObject) + Animation(plt, mktempdir(), ASCIIString[]) +end +Animation() = Animation(current()) + +function frame(anim::Animation) + i = length(anim.frames) + 1 + filename = @sprintf("%06d.png", i) + png(anim.plt, joinpath(anim.dir, filename)) + push!(anim.frames, filename) +end + +function gif(anim::Animation, fn::@compat(AbstractString) = tempname() * ".gif"; fps::Integer = 20) + run(`ffmpeg -framerate $fps -i $(anim.dir)/%06d.png -y $fn`) + info("Saved animation to ", fn) +end \ No newline at end of file diff --git a/src/args.jl b/src/args.jl index c77445fb..1e253a1b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -618,9 +618,9 @@ function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::I aliasesAndAutopick(d, :markershape, _markerAliases, supportedMarkers(pkg), plotIndex) # update color - dumpdict(d, "before color") + # dumpdict(d, "before color") d[:color] = getSeriesRGBColor(d[:color], initargs, plotIndex) - dumpdict(d, "after color") + # dumpdict(d, "after color") # update markercolor mc = d[:markercolor] diff --git a/src/plot.jl b/src/plot.jl index 0617c68a..74edb2f3 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -102,7 +102,7 @@ function plot!(plt::Plot, args...; kw...) preparePlotUpdate(plt) # get the list of dictionaries, one per series - dumpdict(d, "before createKWargsList") + # dumpdict(d, "before createKWargsList") kwList, xmeta, ymeta = createKWargsList(plt, groupargs..., args...; d...) # if we were able to extract guide information from the series inputs, then update the plot