1
+ using GLMakie
2
+ include (" AngleDoubling.jl" )
3
+
4
+ # for each internal address, calculate a screen which shows the future options
5
+
6
+ function drawwedges! (ax,AIA)
7
+ N = AIA. addr[end ]
8
+ n = 5
9
+ for ii in N+ 1 : N+ n
10
+ k = denominator (AIA,ii)
11
+ angles = []
12
+ for jj in 1 : k- 1
13
+ if gcd (jj,k) == 1
14
+ push! (angles,(jj- 0.5 )* 2 * pi / (k- 1 ))
15
+ end
16
+ end
17
+ r = (2 ^ ii+ 2 ^ (ii- 1 ))/ 2
18
+ centers = [(r* cos (theta),r* sin (theta)) for theta in angles]
19
+ pie! (ax,ones (k- 1 ),radius = 2 ^ ii, inner_radius = 2 ^ (ii- 1 ))
20
+ text! (ax,centers,text = fill (" $ii " ,length (centers)), align = (:center ,:center ))
21
+ end
22
+ end
23
+
24
+ function phonebook! (gl,AIA)
25
+ label = Label (gl[2 ,1 ],repr (AIA[]))
26
+ rowsize! (gl, 1 , Aspect (1 , 1.0 ))
27
+ ax1 = Axis (gl[1 ,1 ],aspect = 1 )
28
+ drawwedges! (ax1,AIA[])
29
+
30
+ hidedecorations! (ax1)
31
+ hidespines! (ax1)
32
+ deactivate_interaction! (ax1, :rectanglezoom )
33
+ deactivate_interaction! (ax1, :dragpan )
34
+
35
+ register_interaction! (ax1, :select ) do event:: MouseEvent , ax1
36
+ if event. type === MouseEventTypes. leftdown
37
+ ang = atan (event. data[2 ],event. data[1 ])
38
+ rad = sqrt (sum ([x* x for x in event. data]))
39
+ idx = Int (ceil (log2 (rad)))
40
+ if idx > 0
41
+ k = denominator (AIA[],idx)
42
+ num = Int (mod1 (ceil (ang* (k- 1 )/ (2 * pi )),k- 1 ))
43
+ println (" $idx and $num / $k " )
44
+ if gcd (num,k) == 1
45
+ newaddr = push! (copy (AIA[]. addr),idx)
46
+ newangles = push! (copy (AIA[]. angles),Rational (num,k))
47
+ AIA[] = AngledInternalAddress (newaddr,newangles)
48
+ println (AIA[])
49
+ empty! (ax1)
50
+ drawwedges! (ax1,AIA[])
51
+ label. text = repr (AIA[])
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+
58
+
59
+ end
60
+
61
+
62
+ fig = Figure ()
63
+ ga = fig[1 , 1 ] = GridLayout ()
64
+
65
+ AIA = Observable (AngledInternalAddress ([1 ],[]))
66
+
67
+ phonebook! (ga,AIA)
68
+
69
+ fig
0 commit comments