Changeset 564 for mds-and-trees
- Timestamp:
- 08/05/16 23:25:02 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/tree-genealogy.py
r563 r564 25 25 26 26 def svg_generate_line_style(percent): 27 # hotdog 27 28 from_col = [100, 70, 0] 28 to_col = [100, 0, 0] 29 # from_col = [0, 100, 50] 30 # to_col = [20, 0, 100] 31 32 percent = 1 - ((1-percent)**10) 29 to_col = [60, 0, 0] 30 # neon 31 # from_col = [30, 200, 255] 32 # to_col = [240, 0, 220] 33 34 from_opa = 0.2 35 to_opa = 1.0 36 from_stroke = 1 37 to_stroke = 3 38 39 opa = from_opa*(1-percent) + to_opa*percent 40 stroke = from_stroke*(1-percent) + to_stroke*percent 41 42 percent = 1 - ((1-percent)**20) 33 43 34 44 return 'stroke="rgb(' + str(from_col[0]*(1-percent) + to_col[0]*percent) + '%,' \ 35 45 + str(from_col[1]*(1-percent) + to_col[1]*percent) + '%,' \ 36 + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" stroke-width=" 1" stroke-opacity="0.8"'46 + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" stroke-width="' + str(stroke) + '" stroke-opacity="' + str(opa) + '"' 37 47 38 48 def svg_generate_dot_style(percent): 39 49 from_col = [100, 90, 0] 40 to_col = [100, 0, 0] 41 # from_col = [0, 100, 50] 42 # to_col = [20, 0, 100] 43 44 percent = 1 - ((1-percent)**10) 50 to_col = [60, 0, 0] 51 # neon 52 # from_col = [30, 200, 255] 53 # to_col = [240, 0, 220] 54 55 from_opa = 0.2 56 to_opa = 1.0 57 58 opa = from_opa*(1-percent) + to_opa*percent 59 60 percent = 1 - ((1-percent)**20) 45 61 46 62 return 'fill="rgb(' + str(from_col[0]*(1-percent) + to_col[0]*percent) + '%,' \ 47 63 + str(from_col[1]*(1-percent) + to_col[1]*percent) + '%,' \ 48 + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" r="1.5" stroke="black" stroke-width="0.2"' #fill-opacity="0.5"' 64 + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" r="1.5" stroke="black" stroke-width="0.2" fill-opacity="' + str(opa) + '" ' \ 65 'stroke-opacity="' + str(opa) + '"' 49 66 50 67 # ------------------- … … 60 77 #print("B" +str(creature)) 61 78 if "FromIDs" in creature: 79 assert(len(creature["FromIDs"]) == 1) 62 80 nodes[creature["ID"]] = creature["FromIDs"][0] 63 81 if not creature["FromIDs"][0] in nodes: … … 131 149 for c in inv_nodes[node]: 132 150 #print(node + "->" + c) 133 dissimilarity = random.gauss(0,0.3)151 dissimilarity = 0.5 #random.gauss(0,0.3) 134 152 if TIME == "REAL": 135 153 id = "" … … 165 183 if c in inv_nodes: 166 184 draw_children_recurrent(c, max_depth) 185 186 line_style = (svg_line_style if args.mono_tree else svg_generate_line_style(depth[c]/max_depth)) 187 dot_style = (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[c]/max_depth)) 188 167 189 svg_add_line( (w_margin+w_no_margs*(positions[node][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[node][1]/max_height), 168 (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), 169 (svg_line_style if args.mono_tree else svg_generate_line_style(depth[c]/max_depth))) 170 svg_add_dot( (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), 171 (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[c]/max_depth))) 190 (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), line_style) 191 svg_add_dot( (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), dot_style) 172 192 def draw_children(): 173 193 max_depth = 0 … … 175 195 max_depth = max(max_depth, v) 176 196 draw_children_recurrent(firstnode, max_depth) 177 svg_add_dot( (w_margin+w_no_margs*(positions[firstnode][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[firstnode][1]/max_height),178 (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[firstnode]/max_depth)))197 dot_style = (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[firstnode]/max_depth)) 198 svg_add_dot( (w_margin+w_no_margs*(positions[firstnode][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[firstnode][1]/max_height), dot_style) 179 199 180 200 def draw_spine_recurrent(node): … … 184 204 if c in inv_nodes: 185 205 draw_spine_recurrent(c) 206 207 line_style = svg_spine_line_style 186 208 svg_add_line( (w_margin+w_no_margs*(positions[node][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[node][1]/max_height), 187 (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), svg_spine_line_style)209 (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), line_style) 188 210 #svg_add_dot( (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), svg_spine_dot_style) 189 211 def draw_spine(): … … 197 219 if c in inv_nodes: 198 220 draw_skeleton_reccurent(c, max_depth) 221 222 line_style = svg_spine_line_style 199 223 svg_add_line( (w_margin+w_no_margs*(positions[node][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[node][1]/max_height), 200 (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), 201 svg_spine_line_style) 224 (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), line_style) 202 225 #svg_add_dot( (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), 203 226 # svg_spine_dot_style) … … 210 233 #svg_add_dot( (w_margin+w_no_margs*(positions[firstnode][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[firstnode][1]/max_height), 211 234 # svg_spine_dot_style) 212 213 235 214 236
Note: See TracChangeset
for help on using the changeset viewer.