-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcosmic-dance.jl
executable file
·59 lines (44 loc) · 1.44 KB
/
cosmic-dance.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Javis
function object(r,p=O, color="black")
sethue(color)
circle(p, r, :fill)
return p
end
function connector!(connection,p1, p2, color)
sethue(color)
push!(connection,[p1,p2])
map(x->line(x[1],x[2], :stroke),connection)
end
function ground(args...)
background("black") # canvas background
sethue("white") # pen color
# circle(O,50,:fill)
end
function circ(p = O, color = "black", action = :fill, radius = 25, edge = "solid")
sethue(color)
setdash(edge)
circle(p, radius, action)
end
function make_animation()
# to store the connectors
connection = []
frames = 1000
# setup the video
myvideo = Video(500,500)
Background(1:frames,ground)
# add the objects
earth = Object(1:frames,(args...)->object(5,O,"blue"),Point(200,0))
venus = Object(1:frames,(args...)->object(4,O,"red"),Point(144,0))
#sun = Object(1:frames,(aegs...)->object(50,O,"yellow"),Point(0,0))
# draw the orbits
earth_orbit = Object((args...) -> circ(O, "white", :stroke, 200))
venus_orbit = Object((args...) -> circ(O, "white", :stroke, 144))
# move the planets
act!(earth, Action(anim_rotate_around(12.5*2π, O)))
act!(venus, Action(anim_rotate_around(12.5*2π*(224.7/365), O)))
# draw the connectors
Object(1:frames, (args...)->connector!(connection,pos(earth), pos(venus), "#f05a4f"))
# render
render(myvideo,pathname = "cosmic_dance.gif")
end
make_animation()