-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcross.html
More file actions
105 lines (97 loc) · 2.16 KB
/
Copy pathcross.html
File metadata and controls
105 lines (97 loc) · 2.16 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cross product viewer</title>
</head>
<body>
<canvas id="canva"></canvas>
<script src="utils.js"></script>
<script>
let vecA = {
x1: canva.width / 2,
y1: canva.height / 2,
x2: canva.width / 2,
y2: canva.height / 2 - 100,
color: "blue"
};
let vecB = {
x1: canva.width / 2,
y1: canva.height / 2,
x2: canva.width / 2 + 100,
y2: canva.height / 2,
color: "red"
};
function drawInfos() {
ctx.font = "1.5rem serif";
var yoffset = 0;
ctx.fillText("Drag left click: move blue vector direction",
0,
(yoffset += 25)
);
ctx.fillText("Drag right click: move blue vector direction",
0,
(yoffset += 25)
);
ctx.fillText("CTRL + Drag left click: both vector origine",
0,
(yoffset += 25)
);
var yoffset = 0;
var va = vector(vecA);
var vb = vector(vecB);
ctx.fillText("blue vec: x: " + va.x + " y: " + -va.y,
canva.width / 2,
canva.height / 2 + (yoffset += 25)
);
ctx.fillText("red vec: x: " + vb.x + " y: " + -vb.y,
canva.width / 2,
canva.height / 2 + (yoffset += 25)
);
ctx.fillText("cross product: " + cross(va, vb),
canva.width / 2,
canva.height / 2 + (yoffset += 25)
);
}
function render() {
clearCanva();
drawVector(vecA);
drawVector(vecB);
drawInfos();
}
window.addEventListener("resize", (event) => {
fullScreenCanva();
render();
})
window.addEventListener("load", (event) => {
fullScreenCanva();
render();
});
canva.addEventListener('contextmenu', (event) => {
event.preventDefault()
render();
});
canva.addEventListener("mouseup", (event) => {
render();
})
canva.addEventListener("mousemove", (event) => {
if (event.ctrlKey && event.buttons == 1) {
vecA.x1 = event.clientX;
vecA.y1 = event.clientY;
vecB.x1 = event.clientX;
vecB.y1 = event.clientY;
}
if (!event.ctrlKey && event.buttons == 1) {
vecA.x2 = event.clientX;
vecA.y2 = event.clientY;
}
if (!event.ctrlKey && event.buttons == 2) {
vecB.x2 = event.clientX;
vecB.y2 = event.clientY;
}
render();
});
</script>
</body>
</html>