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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
$include "info.icn"
$define Win_Size 600
# set the default for DrawTree_Square_R
procedure drawtree_rectangle_default(fg, bg)
local draw_record
draw_record := DrawTree_Square_R()
draw_record.win_width := Win_Size + 200
draw_record.win_height := Win_Size - 200
if /fg then draw_record.fg := FG else draw_record.fg := fg
if /bg then draw_record.bg := BG else draw_record.bg := bg
draw_record.color_list := COLOR_LIST
draw_record.color_list_u := COLOR_LIST_U
draw_record.num_color := 4 # take thins out
draw_record.win := WOpen("canvas=hidden", "size=" || Win_Size + 200 || "," || Win_Size,
"bg=" || draw_record.bg, "fg=" || draw_record.fg)
draw_record.linewidth := 10
draw_record.length := Win_Size + 200 - 20
draw_record.space := 2
draw_record.move := 15
draw_record.x := draw_record.move
draw_record.y := 10
draw_record.tree := &null
draw_record.generation := 0
draw_record.num_children_code := &null
draw_record.color_children := &null
draw_record.menu := ["background", format_rectangle_cb, "color list", format_rectangle_cb,
"linewidth", format_rectangle_cb,
"space", format_rectangle_cb, "length", format_rectangle_cb,
"generation", format_rectangle_cb, "tree", format_rectangle_cb,
"color format", format_rectangle_cb, "# of children", format_rectangle_cb,
"snapshot", format_rectangle_cb]
return draw_record
end
# draw the tree in a circle seperated with line between each node
procedure drawtree_rectangle(draw_record, children)
local gen, id, win, size, x, y, num
win := Clone(draw_record.win)
EraseArea(win)
\draw_record.num_children_code & num := children.num_children / *draw_record.color_list
# draw all the children
every id := 0 to children.num_children do
{
/num & Fg(win, draw_record.color_list_u[(draw_record.color_list[(children.all[id].generation) %
draw_record.num_color + 1])])
\num & Fg(win, draw_record.color_list_u[draw_record.color_list[
integer((children.all[id].children_num / num) + 1)]]) |
Fg(win, draw_record.color_list_u[draw_record.color_list[
integer((children.all[id].children_num / num))]])
\draw_record.color_children & draw_record.color_children == *children.all[id].children_id &
Fg(win, "gray")
x := (children.all[id].base * draw_record.length) / (2 * &pi) + 10
size := (((children.all[id].bound - children.all[id].base) * draw_record.length) / (2 * &pi))
y := children.all[id].generation * draw_record.linewidth + 10
FillRectangle(win, x, y, size, draw_record.linewidth - draw_record.space)
}
every id := 0 to children.num_children do
{
x := (children.all[id].base * draw_record.length) / (2 * &pi) + 10
size := (((children.all[id].bound - children.all[id].base) * draw_record.length) / (2 * &pi))
y := children.all[id].generation * draw_record.linewidth + 10
Fg(win, draw_record.bg)
DrawLine(win, x, y, x, y + draw_record.linewidth)
}
if draw_record.generation > 0 then drawtree_rec_gen_find(draw_record, children)
\draw_record.tree & drawtree_rectangle_line(draw_record, children, 0)
return
end
# draw the tree by lines
procedure drawtree_rectangle_line(draw_record, children, id)
local win, new_id, radius, new_radius, y_new, x_new, x, y, size
size := 2
win := Clone(draw_record.win)
Fg("black")
every new_id := !children.all[id].children_id do {
x := (((children.all[id].base + children.all[id].bound)/2) * draw_record.length) / (2 * &pi) + 10
y := (children.all[id].generation) * draw_record.linewidth + 10 + draw_record.linewidth/2
x_new := (((children.all[new_id].base + children.all[new_id].bound)/2) * draw_record.length) / (2 * &pi) + 10
y_new := (children.all[new_id].generation)* draw_record.linewidth + 10 + draw_record.linewidth/2
DrawLine(win, x, y, x_new, y_new)
size := 2
\draw_record.color_children & draw_record.color_children == *children.all[new_id].children_id &
size := 5
FillCircle(win, x, y, size)
FillCircle(win, x_new, y_new, size)
drawtree_rectangle_line(draw_record, children, new_id)
}
return
end
# color code by number of children
procedure drawtree_rec_gen_find(draw_record, children)
local num, id, color_n, first, second, third, gen
gen := draw_record.generation
num := 0
every id := 0 to children.num_children do
{
if children.all[id].generation == gen then
num +:= 1
}
num := MAX_COL / num
color_n := BLUE
every id := 0 to children.num_children do
{
if children.all[id].generation == gen then {
drawtree_rec_gen(draw_record, children, id, color_n)
color_n ? {
first := tab(upto(",")); move(1)
second := tab(upto(",")); move(1)
third := tab(0)
}
second := integer(second) + num
third := integer(third) - num
color_n := string(first) || "," || string(second) || "," || string(third)
}
}
Fg("black")
return
end
# draw the tree
procedure drawtree_rec_gen(draw_record, children, id, color_n)
local gen, new_id, win, size, x, y
win := Clone(draw_record.win)
Fg(win, color_n)
# draw all the children
every new_id := !children.all[id].children_id do
{
x := (children.all[new_id].base * draw_record.length) / (2 * &pi) + 10
size := (((children.all[new_id].bound - children.all[new_id].base) * draw_record.length) / (2 * &pi))
y := children.all[new_id].generation * draw_record.linewidth + 10
FillRectangle(win, x, y, size, draw_record.linewidth - draw_record.space)
drawtree_rec_gen(draw_record, children, new_id, color_n)
}
every new_id := !children.all[id].children_id do
{
x := (children.all[new_id].base * draw_record.length) / (2 * &pi) + 10
size := (((children.all[new_id].bound - children.all[new_id].base) * draw_record.length) / (2 * &pi))
y := children.all[new_id].generation * draw_record.linewidth + 10
Fg(win, draw_record.bg)
DrawLine(win, x, y, x, y + draw_record.linewidth)
}
return
end
|