Created
July 31, 2020 10:05
-
-
Save jkrumbiegel/7b7e263e957610a853574ca768de93bb to your computer and use it in GitHub Desktop.
layered.jl grid animations.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Layered | |
using Animations | |
using VideoIO | |
using Colors | |
let | |
prev = pwd() | |
try | |
mktempdir() do path | |
cd(path) | |
map(enumerate(0:1/60:3)) do (i, t) | |
c, l = canvas(600, 400) | |
w, h = 560, 360 | |
ps1 = P.(-w/2, -h/2:20:h/2) | |
ps2 = P.(w/2, -h/2:20:h/2) | |
ps3 = P.(-w/2:20:w/2, -h/2) | |
ps4 = P.(-w/2:20:w/2, h/2) | |
panims1 = Animation.( | |
LinRange(0.5, 1.5, length(ps1)), ps1, | |
sineio(), | |
LinRange(1.5, 2.5, length(ps1)), ps2 | |
) | |
panims2 = Animation.( | |
LinRange(0.5, 1.5, length(ps3)), ps3, | |
sineio(), | |
LinRange(1.5, 2.5, length(ps3)), ps4 | |
) | |
coloranims1 = Animation.( | |
LinRange(0.5, 1.5, length(ps1)), RGB(1.0, 0, 0), | |
sineio(), | |
LinRange(1.5, 2.5, length(ps1)), RGB(0.0, 0, 0) | |
) | |
coloranims2 = Animation.( | |
LinRange(0.5, 1.5, length(ps3)), RGB(0.0, 1.0, 0), | |
sineio(), | |
LinRange(1.5, 2.5, length(ps3)), RGB(0.0, 0, 0) | |
) | |
lines!(l) do | |
Line.(ps1, at.(panims1, t)) | |
end + Stroke(at.(coloranims1, t)) | |
lines!(l) do | |
Line.(ps3, at.(panims2, t)) | |
end + Stroke(at.(coloranims2, t)) | |
csurface = Layered.draw_rgba(c, px_per_pt=0.75) | |
png(c, "$(lpad(i, 4, '0')).png") | |
end | |
run(`ffmpeg -framerate 60 -i %4d.png -crf 23 video.mp4`) | |
cp("video.mp4", joinpath(prev, "video.mp4"), force = true) | |
cd(prev) | |
end | |
finally | |
cd(prev) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment