-
Notifications
You must be signed in to change notification settings - Fork 0
/
solving_sol_11.js
100 lines (80 loc) · 2.67 KB
/
solving_sol_11.js
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
const canvasSketch = require("canvas-sketch");
const settings = {
dimensions: [2048, 2048],
};
const margin = 50;
const lineDiff = 200;
const generateQuardentPoints = (xMin, yMin, xMax, yMax) => {
return { xMin, xMax, yMin, yMax };
};
const encodeCoords = (point, center) => {
return Math.round((point - center) / 10);
};
const decodeCoords = (point, center) => {
return Math.round((point + center) * 10);
};
const sketch = () => {
return ({ context, width, height }) => {
let centerX = width / 2;
let centerY = height / 2;
context.translate(centerX, centerY);
context.rotate((3 * Math.PI) / 2);
width = width - margin;
height = height - margin;
centerX = width / 2;
centerY = height / 2;
context.strokeStyle = "black";
context.strokeRect(-centerX, -centerY, width, height);
const q1 = generateQuardentPoints(0, 0, centerX, centerY);
const q2 = generateQuardentPoints(-centerX, 0, 0, centerY);
const q3 = generateQuardentPoints(-centerX, -centerY, 0, 0);
const q4 = generateQuardentPoints(0, -centerY, centerX, 0);
const plotPoints = (q, color) => {
const { xMin, xMax, yMin, yMax } = q;
for (let x = xMin; x <= xMax; x += lineDiff) {
for (let y = yMin; y <= yMax; y += lineDiff) {
context.beginPath();
context.fillStyle = color;
context.arc(x, y, 10, 0, Math.PI * 2, false);
context.fill();
}
}
};
plotPoints(q4, "red");
// context.beginPath();
// context.fillStyle = "#fff";
// context.font = "35px Arial";
// context.fillText(
// `{${encodeCoords(centerX, centerX)},${encodeCoords(centerY, centerY)}}`,
// centerX,
// centerY
// );
const plotCoords = (minX, minY, maxX, maxY) => {
for (let x = minX; x < maxX; x += lineDiff) {
for (let y = minY; y < maxY; y += lineDiff) {
context.beginPath();
context.fillStyle = "#000";
context.font = "35px Arial";
context.fillText(`{${x / 100},${y / 100}}`, x, y);
}
}
};
plotCoords(-centerX, -centerY, centerX, centerY);
// const plotPoints = (minX, minY, maxX, maxY) => {
// for (let x = minX; x <= maxX; x += lineDiff) {
// for (let y = minY; y <= maxY; y += lineDiff) {
// context.beginPath();
// context.fillStyle = "#fff";
// context.font = "35px Arial";
// context.fillText(
// `{${encodeCoords(x, centerX)},${encodeCoords(y, centerY)}}`,
// x,
// y
// );
// }
// }
// };
// plotPoints(margin, margin, width - margin, height - margin);
};
};
canvasSketch(sketch, settings);