Created
February 8, 2022 09:58
-
-
Save somacdivad/e821f9d9b789e35aa944382b080bb58f to your computer and use it in GitHub Desktop.
Makes an animation of four circle growing and shrinking while changing color.
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 Javis | |
using ColorSchemes | |
# Set the color scheme | |
# More options: | |
# https://juliagraphics.github.io/ColorSchemes.jl/stable/catalogue/ | |
colors = ColorSchemes.cool | |
function circ(radius, color="white") | |
sethue(color) # Set the color of the circle | |
setdash("solid") # Set the edge style | |
setline(8) # Set the linewidth | |
# Draw a circle with `radius` centered at the origin | |
circle(O, radius, :stroke) | |
end | |
# Create a 500px × 500px video with 100 frames | |
video = Video(500, 500) | |
num_frames = 100 | |
# Set the background for each frame | |
Background(1:num_frames, (args...) -> background("black")) | |
# Radius of circle i in frame t | |
r(t, i) = 200sin(2π*t/num_frames) + 10i | |
# Color of circle i in frame t | |
c(t, i) = colors[min(t + 10(i-1), 100)] | |
# Draw four circles with radii that grow and shrink colors that change. | |
for i in 1:4 | |
Object(1:num_frames, (_, _, t) -> circ(r(t-i, i), c(t, i))) | |
end | |
# Render the video at 24 frames per second | |
render(video, pathname="circle.gif", framerate=24) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment