Skip to content

Instantly share code, notes, and snippets.

@goerz
Forked from cormullion/animation-sketch.jl
Created June 8, 2023 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goerz/93de788984e4219f838a2e09f31db4d3 to your computer and use it in GitHub Desktop.
Save goerz/93de788984e4219f838a2e09f31db4d3 to your computer and use it in GitHub Desktop.
an animated something
using Luxor, Thebes, MathTeXEngine
function frame(scene, framenumber)
background("white")
sethue("black")
fontsize(15)
eased_n = scene.easingfunction(framenumber, 0, 1, scene.framerange.stop)
helloworld()
eyepoint(200, 200, 100)
setline(0.5)
radius = 150
path = [sphericaltocartesian(radius, θ, π / 2) for θ in -π:π/30:π]
# grey disk
@layer begin
sethue("grey80")
poly(pin.(path), :fillpreserve)
setdash([10, 20])
strokepath()
end
# path outline
pin(path)
# arrow and radius
arrow(O, pin(sphericaltocartesian(radius, π, π / 2)))
text(L"radius", midpoint(O, pin(sphericaltocartesian(radius, π, π / 2)) + (20, 20)))
# calculate positions for this frame
pos1 = sphericaltocartesian(radius, -π + eased_n * 2π, π/2)
pos2 = sphericaltocartesian(radius, -π - eased_n * 2π, π/2)
# draw the thingy1
@layer begin
translate(pin(pos1))
sethue("red")
# can't do LATEX underscore?
text("V_", O + (0, -50)) # shift text up a bit
scale(0.2)
placeimage(image1, O + (0, -100), 0.7, centered=true)
end
# draw the thingy2
@layer begin
translate(pin(pos2))
sethue("green")
text(L"V_+", O + (0, -50))
scale(0.2)
placeimage(image2, O + (0, -100), 0.7, centered=true)
end
end
image1 = readpng(homedir() * "/Desktop/thingy2.png")
image2 = readpng(homedir() * "/Desktop/thingy1.png")
function main()
mov = Movie(500, 300, "mov")
animate(mov, [Scene(mov, frame, 1:130, easingfunction=easeinoutquad)],
creategif=true, framerate=25)
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment