summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2024-04-16 19:48:59 +0300
committerMartial Simon <msimon_fr@hotmail.com>2024-04-16 19:48:59 +0300
commit0deb0d6e9e85a169571240de634d958183c56b56 (patch)
treeae48a2b74bd7129a7db76d36b6d06525dac902a2 /index.js
parent68f82a122922d2658b9f296ff35f1d4e2546060c (diff)
proto: patching robot movement
Diffstat (limited to 'index.js')
-rw-r--r--index.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/index.js b/index.js
index 58617f1..b4b6154 100644
--- a/index.js
+++ b/index.js
@@ -43,6 +43,8 @@ canvas.addEventListener('mousedown', (e) => {
cross.style.left = e.layerX - canvasOffsetX + "px"
cross.style.top = e.layerY - canvasOffsetY + "px"
+
+ temp = angle
angle = Math.atan(x/Math.abs(y))
sym = 1
@@ -53,9 +55,14 @@ canvas.addEventListener('mousedown', (e) => {
if (y > 0) {
angle = sym*Math.PI - angle
}
+ console.log(temp)
+ console.log(angle)
robot.style.transform = 'translate(-50%, -50%) rotate('+ angle +'rad)';
- moveTo(x * scale,y * scale)
+ a = -(e.layerX - canvasOffsetX - canvas.width/2) * scale
+ b = -(e.layerY - canvasOffsetY - canvas.height/2) * scale
+ rot = (angle - temp)
+ moveTo(a*Math.cos(-rot)- b * Math.sin(-rot),a * Math.sin(-rot) + b*Math.cos(-rot))
moveAll(x,y)
});
@@ -109,6 +116,9 @@ reset.onclick = () => {
drawings = [];
angle = 0
robot.style.transform = 'translate(-50%, -50%) rotate(0deg)';
+ a = canvas.width/2 + canvasOffsetX;
+ b = canvas.height/2 + canvasOffsetY;
+ ctx.clearRect(-a,-b,canvas.width,canvas.height);
}
function resizeCanvas() {