-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.js
More file actions
38 lines (33 loc) · 947 Bytes
/
Grid.js
File metadata and controls
38 lines (33 loc) · 947 Bytes
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
class PolarGrid {
constructor(x, y, step, count) {
this._x = x;
this._y = y;
this._step = step;
this._count = count;
}
get maxSize() {
return this._step * this._count;
}
/** @param {CanvasRenderingContext2D} ctx */
draw(ctx) {
ctx.save();
ctx.globalAlpha = 0.5;
ctx.translate(this._x, this._y);
// cross
ctx.beginPath();
ctx.moveTo(-(this._count + 0.5) * this._step, 0);
ctx.lineTo((this._count + 0.5) * this._step, 0);
ctx.moveTo(0, -(this._count + 0.5) * this._step);
ctx.lineTo(0, (this._count + 0.5) * this._step);
ctx.closePath();
ctx.stroke();
// circles
ctx.beginPath();
for (let i = 0; i <= this._count; ++i) {
ctx.arc(0, 0, i * this._step, 0, 2 * Math.PI);
}
ctx.closePath();
ctx.stroke();
ctx.restore();
}
}