-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawing.js
More file actions
56 lines (51 loc) · 1.8 KB
/
Copy pathdrawing.js
File metadata and controls
56 lines (51 loc) · 1.8 KB
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
import Polygon from "./polygon.js";
import Datas from "./datas.js";
export default class Drawing {
constructor(selector) {
this.selectorOfSheet = selector;
this.drawing = SVG().addTo(this.selectorOfSheet).size(600, 600);
this.rect = this.drawing.rect(600, 600).attr({ fill: "gray" });
}
reset = (from = 72) => {
clearTimeout(this.timer);
this.row = 0;
this.pos = 0;
Polygon.serNum = 0;
let hexagons = document.querySelectorAll(
this.selectorOfSheet + " > svg > polygon"
);
hexagons.forEach((polygon, index) => {
if (this.selectorOfSheet == "#editor" && index > from) polygon.remove();
if (this.selectorOfSheet == "#backstrap") polygon.remove();
});
};
initDraw(nameOfPattern, middle, yShift, maxRow, lefty = 0) {
let draw = () => {
direction = this.row % 2 ? -1 : 1;
y = yShift + this.row * 41;
pattern = this.pattNow[Datas.backstraps.healds[this.row % 2]];
x = middle - pattern.length * 8;
x =
x + (this.row % 2) * lefty * 16 + this.pos * 16 + direction * corr * -1;
color = Datas.backstraps.colors[pattern[this.pos]];
new Polygon(this.drawing, x, y, color);
this.pos = this.pos + direction;
if (this.pos === pattern.length || this.pos === -1)
this.pos =
(++this.row % 2) *
(this.pattNow[Datas.backstraps.healds[this.row % 2]].length - 1);
this.timer = setTimeout(() => draw(), (37 / pattern.length) * 10);
if (this.row === maxRow) {
clearTimeout(this.timer);
this.row = 0;
this.pos = 0;
}
};
this.timer;
this.reset();
this.pattNow = Datas.backstraps.patterns[nameOfPattern];
let corr = this.pattNow.upper.length === this.pattNow.lower.length ? 4 : 0;
let direction, x, y, pattern, color;
draw();
}
}