-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-game-record-form.html
232 lines (215 loc) · 7.1 KB
/
go-game-record-form.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Cutive&display=swap"
rel="stylesheet"
/>
<title>Go game record</title>
<style>
@page {
size: A4;
}
body {
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
height: 100vh;
justify-content: space-around;
font-family: "Cutive";
}
svg {
width: 100%;
height: auto;
}
.header {
width: 100%;
}
.header h1 {
text-align: center;
}
.header table {
width: 100%;
}
.header table tr {
display: flex;
margin-bottom: 0.5em;
}
.header table tr td {
flex: 2;
display: flex;
}
.header table tr td:first-of-type {
flex: 3;
}
.header table tr td label {
margin-left: 0.5em;
margin-right: 0.5em;
}
.header table tr td label::after {
content: ":";
}
.header table tr td input {
flex: 1;
background: transparent;
border: none;
border-bottom: 1px solid black;
margin-left: 0.5em;
margin-right: 0.5em;
}
.footer {
text-align: center;
border: 1px solid black;
height: 10%;
width: calc(100% - 1em);
}
</style>
</head>
<body>
<div class="header">
<h1>Go game record</h1>
<table>
<tr>
<td>
<label>Event</label>
<input type="text" />
</td>
<td>
<label>Date</label>
<input type="text" />
</td>
</tr>
<tr>
<td>
<label>Black</label>
<input type="text" />
</td>
<td>
<label>Handicap</label>
<input type="text" />
</td>
</tr>
<tr>
<td>
<label>White</label>
<input type="text" />
</td>
<td>
<label>Komi</label>
<input type="text" />
</td>
</tr>
<tr>
<td>
<label>Time limit</label>
<input type="text" />
</td>
<td>
<label>Result</label>
<input type="text" />
</td>
</tr>
</table>
</div>
<svg
id="board"
xmlns="http://www.w3.org/2000/svg"
preserveAspectRatio="xMidYMid meet"
></svg>
<div class="footer"></div>
<script>
// Source: https://en.wikipedia.org/wiki/Go_equipment
const boardSize = 19; // Standard Go board size
const lineSpacingWidthWise = 22;
const lineSpacingLengthWise = 23.7;
const lineThickness = 1;
const starPointDiameter = 4;
const stoneDiameter = 22.5;
const sizeRatio = 1;
const margin = stoneDiameter * sizeRatio;
function boardPositionToCoordinates(row, column) {
x = column * (lineSpacingWidthWise + lineThickness) + lineThickness / 2;
y = row * (lineSpacingLengthWise + lineThickness) + lineThickness / 2;
return [x * sizeRatio + margin, y * sizeRatio + margin];
}
const board = document.getElementById("board");
viewWidth =
((boardSize + 2) * lineThickness +
(boardSize + 1) * lineSpacingWidthWise) *
sizeRatio +
2 * margin;
viewLength =
((boardSize + 2) * lineThickness +
(boardSize + 1) * lineSpacingLengthWise) *
sizeRatio +
2 * margin;
board.setAttribute("viewBox", `0 0 ${viewWidth} ${viewLength}`);
// Draw stones
for (let row = 1; row <= boardSize; row++) {
for (let column = 1; column <= boardSize; column++) {
strokeWidth = lineThickness * sizeRatio;
radius = ((stoneDiameter + lineThickness / 2) / 2) * sizeRatio;
[x, y] = boardPositionToCoordinates(row, column);
board.innerHTML += `<circle cx="${x}" cy="${y}" r="${radius}" style="fill: none; stroke: #ddd; stroke-width: ${strokeWidth};"/>`;
}
}
// Draw lines
for (let i = 1; i <= boardSize; i++) {
strokeWidth = lineThickness * sizeRatio;
// Horizontal lines
[startRow, startColumn] = [i, 1];
[endRow, endColumn] = [i, boardSize];
[x1, y1] = boardPositionToCoordinates(startRow, startColumn);
[x2, y2] = boardPositionToCoordinates(endRow, endColumn);
x1 -= strokeWidth / 2;
x2 += strokeWidth / 2;
board.innerHTML += `<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" style="stroke: black; stroke-width: ${strokeWidth}"/>`;
// Vertical lines
[startRow, startColumn] = [1, i];
[endRow, endColumn] = [boardSize, i];
[x1, y1] = boardPositionToCoordinates(startRow, startColumn);
[x2, y2] = boardPositionToCoordinates(endRow, endColumn);
y1 -= strokeWidth / 2;
y2 += strokeWidth / 2;
board.innerHTML += `<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" style="stroke: black; stroke-width: ${strokeWidth}"/>`;
}
// Draw star points
for (let row = 4; row <= boardSize; row += 6) {
for (let column = 4; column <= boardSize; column += 6) {
radius = (starPointDiameter / 2) * sizeRatio;
[x, y] = boardPositionToCoordinates(row, column);
board.innerHTML += `<circle cx="${x}" cy="${y}" r="${radius}" style="fill: black;"/>`;
}
}
// Draw coordinates
for (let row = 1; row <= boardSize; row++) {
symbol = `${boardSize - row + 1}`;
[x, y] = boardPositionToCoordinates(row, 0);
board.innerHTML += `<text x="${x}" y="${y}" style="fill: black; text-anchor: middle; dominant-baseline: middle; font-size: ${
stoneDiameter * sizeRatio * 0.5
}px;">${symbol}</text>`;
[x, y] = boardPositionToCoordinates(row, boardSize + 1);
board.innerHTML += `<text x="${x}" y="${y}" style="fill: black; text-anchor: middle; dominant-baseline: middle; font-size: ${
stoneDiameter * sizeRatio * 0.5
}px;">${symbol}</text>`;
}
horizontalCoordinates = "ABCDEFGHJKLMNOPQRST"; // no I
for (let column = 1; column <= boardSize; column++) {
symbol = `${horizontalCoordinates[column - 1]}`;
[x, y] = boardPositionToCoordinates(0, column);
board.innerHTML += `<text x="${x}" y="${y}" style="fill: black; text-anchor: middle; dominant-baseline: middle; font-size: ${
stoneDiameter * sizeRatio * 0.5
}px;">${symbol}</text>`;
[x, y] = boardPositionToCoordinates(boardSize + 1, column);
board.innerHTML += `<text x="${x}" y="${y}" style="fill: black; text-anchor: middle; dominant-baseline: middle; font-size: ${
stoneDiameter * sizeRatio * 0.5
}px;">${symbol}</text>`;
}
</script>
</body>
</html>