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
| function fn(){
let rost;// высота древа
let xx=165,yy=210,w=256;
let arr=[
[],
[ ...Array(2**1).keys()].map(i => i+1),
[ ...Array(2**2).keys()].map(i => i+1),
[ ...Array(2**3).keys()].map(i => i+1),
[ ...Array(2**4).keys()].map(i => i+1),
[ ...Array(2**5).keys()].map(i => i+1),
[ ...Array(2**6).keys()].map(i => i+1),
[ ...Array(2**7).keys()].map(i => i+1),
];
arr=arr.map((c,j) => {
let p=w/(c.length*2);
return c.map((x,i) => (xx+(i*2+1)*p-w/2));
});
tree([0,0,0]);
function tree(x){// дерево
let n=x[4];
let cb;
if(x[0]===undefined)return undefined;
let men='';//люди
if((x[1]==0)&&(x[2]==0)){
n=6;
rost=0;
let i=x[0];
// самый дочерний элемент
men='<rect x="'+(xx-15)+'" y="'+(yy)+'" width="30" height="12" fill="blue" stroke="violet"/>\n';
cb=xx;
}
if (x[1]>0 && x[1]<7){
if(rost<x[1])rost=x[1];
bz=[0,90,70,70,34,16,6].map(c => c/3)[x[1]];// ширина квадрата на этажах
arr[x[1]].forEach((c,i) => {if(i==x[2]){
let yh=24;
men+=
'\n<rect x="'+(c-bz/2|0)+'" y="'+(yy-yh*x[1])+'" width="'+(bz|0)+
'" height="12" fill="white" stroke="'+(['blue','violet'][x[2]%2])+'"'+
' />\n';
bush.innerHTML+=
'\n<line x1="'+(c)+'" y1="'+(yy-yh*x[1]+12)+'" x2="'+(x[3])+
'" y2="'+(yy-yh*x[1]+yh-1)+'" />'
cb=c;
}});
}
if(n>0)tree([1,x[1]+1,x[2]*2,cb,n-1]);//вправо
if(n>0)tree([1,x[1]+1,x[2]*2+1,cb,n-1]);//влево
bush.innerHTML+=men;
return rost;
}
}
fn(); |