Skip to content

Instantly share code, notes, and snippets.

@somacdivad
Last active February 10, 2022 14:30
Show Gist options
  • Save somacdivad/0f139b8f9e9ec63340f854dd47aa49b7 to your computer and use it in GitHub Desktop.
Save somacdivad/0f139b8f9e9ec63340f854dd47aa49b7 to your computer and use it in GitHub Desktop.
using Animations
using ColorSchemes
using Javis
N = 6 # number of circles
radius = 20 # Radius of each circles
speed = 5 # degrees per frame
colors = ColorSchemes.rainbow1
video = Video(500, 500)
frames = 240
Background(1:frames, (args...) -> background("black"))
for i in 1:N
θ = -(π/N)*(i-1)
R = 230cos(θ + (speed/360))
p₀ = R*Point(cos(θ), sin(θ))
p₁ = 230*Point(cos(θ), sin(θ))
color_idx = Int(floor(length(colors) / N))*i
circ = Object(@JShape begin
sethue(color)
circle(center, radius, action)
end center=p₀ radius=radius action=:fill color=colors[color_idx])
# This gets close, but doesn't quite produce the desired effect
f₁ = Int(floor(0.5*frames*(i/N)))
f₂ = Int(floor(0.5*frames*(1 + i/N)))
act!(circ, Action(1:f₁, sineio(), anim_translate(p₀, p₁)))
act!(circ, Action(f₁+1:f₂, sineio(), anim_translate(p₁, -p₁)))
act!(circ, Action(f₂+1:frames, sineio(), anim_translate(-p₁, p₀)))
end
render(video, pathname="rotatingcircles.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment