-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw_hilbert.jl
More file actions
55 lines (51 loc) · 2.01 KB
/
Copy pathdraw_hilbert.jl
File metadata and controls
55 lines (51 loc) · 2.01 KB
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
using Luxor, Colors
function hilbert(pointslist::Array{Point, 1},
start::Point, unitx::Point, unity::Point, depth)
if depth <= 0
push!(
pointslist,
Point(start.x + (unitx.x + unity.x)/2, start.y + (unitx.y + unity.y)/2))
else
hilbert(pointslist, start,
Point(unity.x/2, unity.y/2),
Point(unitx.x/2, unitx.y/2),
depth-1)
hilbert(pointslist, Point(start.x + unitx.x/2, start.y + unitx.y/2),
Point(unitx.x/2, unitx.y/2),
Point(unity.x/2, unity.y/2),
depth-1)
hilbert(pointslist, Point(start.x + unitx.x/2 + unity.x/2, start.y + unitx.y/2 + unity.y/2),
Point(unitx.x/2, unitx.y/2),
Point(unity.x/2, unity.y/2),
depth-1)
hilbert(pointslist, Point(start.x + unitx.x/2 + unity.x, start.y + unitx.y/2 + unity.y),
Point(-unity.x/2, -unity.y/2),
Point(-unitx.x/2, -unitx.y/2),
depth-1)
end
return pointslist
end
function frame(scene, framenumber)
background("black")
hilbertcurve, mesh1 = scene.opts
setmesh(mesh1)
setline(3)
eased_n = scene.easingfunction(framenumber, 0, 1, scene.framerange.stop)
hilbertpath = polyportion(hilbertcurve, eased_n, closed=false)
poly(hilbertpath, :stroke)
circle(hilbertpath[end], 8, :fill)
end
function main()
hilbertcurve = hilbert(Point[], O - (128, 128), Point(256, 0), Point(0, 256), 5)
hilbertmovie = Movie(400, 400, "hilbertmovie")
backdrop(scene, framenumber) = background("black")
mesh1 = mesh(ngon(O, 256, 4, π/4, vertices=true), [
RGB(Luxor.julia_red...), RGB(Luxor.julia_green...), RGB(Luxor.julia_purple...), RGB(Luxor.julia_blue...)])
animate(hilbertmovie, [
Scene(hilbertmovie, backdrop, 0:400),
Scene(hilbertmovie, frame, 0:400, optarg = (hilbert=hilbertcurve, mesh=mesh1),
easingfunction=easeinoutsine)],
creategif=true,
pathname="outputs/hilbertanimation.gif")
end
main()