require 'gnuplotrb'
include GnuplotRB
include Math
def generate_heatmaps(initial)
initial.map do
Splot.new(
[initial.shuffle, matrix: true],
pm3d: ['map', interpolate: [8, 8]],
palette: 'grey'
)
end
end
initial_heatmap = [
[6, 5, 4, 3, 1, 0],
[3, 2, 2, 0, 0, 1],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 2, 3],
[0, 0, 1, 2, 4, 3],
[0, 1, 2, 3, 4, 5],
]
Animation.new(*generate_heatmaps(initial_heatmap), animate: { delay: 30 })
def periodic_plots
count = 100
timestep = 2 * PI / count
count.times.map do |i|
angle = i * timestep
Plot.new(["sin(x * 30 - 10 * #{angle}) * exp(-abs(x + 2 * sin(#{angle})))", title: 'Moving sinx'])
end
end
Animation.new(*periodic_plots, xrange: -5..5, yrange: -2..2, samples: 1000)