-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatterneditor.js
More file actions
63 lines (60 loc) · 1.65 KB
/
Copy pathpatterneditor.js
File metadata and controls
63 lines (60 loc) · 1.65 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
57
58
59
60
61
62
63
import Polygon from "./polygon.js";
export default class PatternEditor {
constructor() {
this.editor = document.getElementsByTagName("svg")[1].instance;
this.color = "white";
this.colorsPressed = 0;
this.colorSwitcher();
}
colorSwitcher() {
let colors = document.getElementById("colors");
colors.addEventListener("click", () => {
this.colorsPressed = this.colorsPressed ? 0 : 1;
colors.value = this.colorsPressed + 2 + " szín";
});
}
patternEditor = () => {
let draw = (i, shift) => {
let poly = this.editor.polygon(
Polygon.hex(shift * 8 + (5 + 16 * i), shift * 41 + 10)
);
poly.attr({
"fill-opacity": 0.0001,
stroke: "white",
"stroke-width": 1,
});
let lastColor;
let colorsOrder = {
0: { white: "red", red: "white", black: "white" },
1: { white: "red", red: "black", black: "white" },
};
poly.on("click", (e) => {
lastColor = poly.attr("fill");
if (poly.attr("fill") === "#000000") {
poly.attr({
"fill-opacity": 1,
"stroke-width": 0,
fill: this.color,
});
} else {
this.color = colorsOrder[this.colorsPressed][lastColor];
poly.fill(this.color);
}
});
poly.on(["contextmenu", "dblclick"], (e) => {
e.preventDefault();
poly.attr({
"fill-opacity": 0.0001,
stroke: "white",
"stroke-width": 1,
fill: "#000000",
});
});
};
for (let j = 0; j < 2; j++) {
for (let i = 0; i <= 36 - j; i++) {
draw(i, j);
}
}
};
}