-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
172 lines (156 loc) · 4.28 KB
/
index.html
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
<html>
<head>
<style>
body {
width: 100%;
height: 100%;
margin: 0;
overflow: scroll;
}
svg {
}
svg circle {
stroke: black;
stroke-width: 2;
}
svg circle:hover {
stroke-width: 4;
}
svg path {
fill: none;
}
svg path.full {
stroke-width: 8;
opacity: 0.2;
}
svg path.dash {
stroke-width: 4;
stroke-dasharray: 100 1900;
animation: dash 2s linear reverse infinite;
}
@keyframes dash {
to {
stroke-dashoffset: 2000;
}
}
output {
position: fixed;
}
</style>
</head>
<body>
<svg>
<image href='https://ahs-frc867.github.io/2023-field/field.png' width='100%' height='100%' opacity="0.5"/>
</svg>
<script>
async function main(){
const svg = document.querySelector('svg')
const ns = "http://www.w3.org/2000/svg"
const place_list = await fetch('https://ahs-frc867.github.io/2023-field/field.json').then(res => res.json())
const places = {}
for(const place of place_list){
if(!(place.type in places)) places[place.type] = {}
places[place.type][place.name] = {
x: place.xm * 100,
y: place.ym * 100,
z: place.zm * 100,
enum: place.enum
}
}
const paths = {
left: {
name: 'left',
place_list: [
places.grid_left.approach_left,
places.grid_left.node_left_top,
places.grid_left.approach_left,
places.charge_station.avoid_left_near,
places.charge_station.avoid_left_far,
places.staged_piece.approach_leftmost,
places.staged_piece.leftmost,
places.charge_station.avoid_left_far,
places.charge_station.avoid_left_near,
places.grid_left.approach_middle,
places.grid_left.node_middle_top,
places.grid_left.approach_middle,
places.charge_station.approach_left_near,
places.charge_station.park_left,
],
},
right: {
name: 'right',
place_list: [
places.grid_right.approach_right,
places.grid_right.node_right_top,
places.grid_right.approach_right,
places.charge_station.avoid_right_near,
places.charge_station.avoid_right_far,
places.staged_piece.approach_rightmost,
places.staged_piece.rightmost,
places.charge_station.avoid_right_far,
places.charge_station.avoid_right_near,
places.grid_right.approach_middle,
places.grid_right.node_middle_top,
places.grid_right.approach_middle,
places.charge_station.approach_right_near,
places.charge_station.park_right,
],
},
custom: {
name: 'custom',
place_list: []
}
}
const w = places.field.corner_left_far.x - places.field.corner_left_near.x
const h = places.field.corner_left_far.y - places.field.corner_right_far.y
svg.viewBox = `0 0 ${w} ${h}`
svg.style.width = w
svg.style.height = h
const update_path = path => {
const d = 'M' + path.place_list.map(place => [w/2 + place.x, h/2 - place.y].join(' ')).join('L')
path.full.setAttribute('d', d)
path.dash.setAttribute('d', d)
console.log(path.name + ': { ' + path.place_list.map(a=>a.enum).join(', ') + ' };')
}
let i = 0
for(const name in paths) {
const color = `hsla(${i}, 50%, 50%, 1)`
i += 60
const path = paths[name]
path.full = document.createElementNS(ns, 'path')
path.full.setAttribute('class', 'full')
path.full.setAttribute('stroke', color)
svg.appendChild(path.full)
path.dash = document.createElementNS(ns, 'path')
path.dash.setAttribute('class', 'dash')
path.dash.setAttribute('stroke', color)
svg.appendChild(path.dash)
update_path(path)
}
for(const type in places){
const color = `hsla(${i}, 100%, 80%, 1)`
i += 60
for(const name in places[type]){
const place = places[type][name]
const circle = document.createElementNS(ns, 'circle')
circle.setAttribute('cx', w/2 + place.x)
circle.setAttribute('cy', h/2 - place.y)
circle.setAttribute('r', 4)
circle.setAttribute('fill', color)
circle.addEventListener('click', (event) => {
event.stopPropagation()
paths.custom.place_list.push(place)
update_path(paths.custom)
})
svg.appendChild(circle)
}
}
svg.addEventListener('click', (event) => {
paths.custom.place_list = []
update_path(paths.custom)
})
}
main()
</script>
</body>
</html>