Skip to content

Instantly share code, notes, and snippets.

@aont
Created December 4, 2014 12:50
Show Gist options
  • Select an option

  • Save aont/e42740023d7d39dcbcfa to your computer and use it in GitHub Desktop.

Select an option

Save aont/e42740023d7d39dcbcfa to your computer and use it in GitHub Desktop.
on-the-fly making gnuplot movie
#!/usr/bin/ruby
# coding: utf-8
require 'open3'
Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
gp_in.puts "set term png"
gp_in.puts "set output \"| ffmpeg -y -f image2pipe -i - -vcodec copy out.mp4 >ffmpeg.log 2>&1"
500.times do |i|
delta = 0.1*i
gp_in.puts "plot sin(x+%g)" % delta
gp_in.puts "print \"%d\"" % i
puts gp_err.gets
end
gp_in.puts "set output"
gp_in.puts "print \"end\""
puts gp_err.gets
gp_in.puts "exit"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment