Skip to content

Commit 565dd97

Browse files
authored
Add files via upload
1 parent dcdd369 commit 565dd97

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

main.html

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>seastianLabs</title>
7+
<style>
8+
* {
9+
padding: 0;
10+
margin: 0;
11+
}
12+
13+
canvas {
14+
background: #eee;
15+
display: block;
16+
margin: 0 auto;
17+
}
18+
</style>
19+
</head>
20+
21+
<body>
22+
<canvas id="myCanvas" width="800" height="600"></canvas>
23+
<script>
24+
var canvas = document.getElementById("myCanvas");
25+
var ctx = canvas.getContext("2d");
26+
var rightPressed = false;
27+
var leftPressed = false;
28+
var upPressed = false;
29+
var downPressed = false;
30+
var L1 = 100;
31+
var L2 = 50;
32+
var A1 = 0;
33+
var A2 = 0;
34+
var Pos1x = L1 * Math.cos(A1);
35+
var Pos1y = L1 * Math.sin(A1);
36+
var Pos2x = L2 * Math.cos(A2);
37+
var Pos2y = L2 * Math.sin(A2);
38+
39+
document.addEventListener("keydown", keyDownHandler, false);
40+
document.addEventListener("keyup", keyUpHandler, false);
41+
42+
function keyDownHandler(e) {
43+
if (e.keyCode == 39) {
44+
rightPressed = true;
45+
} else if (e.keyCode == 37) {
46+
leftPressed = true;
47+
} else if (e.keyCode == 38) {
48+
upPressed = true;
49+
} else if (e.keyCode == 40) {
50+
downPressed = true;
51+
}
52+
}
53+
54+
function keyUpHandler(e) {
55+
if (e.keyCode == 39) {
56+
rightPressed = false;
57+
} else if (e.keyCode == 37) {
58+
leftPressed = false;
59+
} else if (e.keyCode == 38) {
60+
upPressed = false;
61+
} else if (e.keyCode == 40) {
62+
downPressed = false;
63+
}
64+
}
65+
66+
function drawBrazo1() {
67+
Pos1x = L1 * Math.cos(A1);
68+
Pos1y = L1 * Math.sin(A1);
69+
ctx.beginPath();
70+
ctx.moveTo(0, 0);
71+
ctx.lineTo(Pos1x, Pos1y);
72+
ctx.stroke();
73+
ctx.closePath();
74+
}
75+
76+
function drawBrazo2() {
77+
Pos2x = L2 * Math.cos(A2);
78+
Pos2y = L2 * Math.sin(A2);
79+
ctx.beginPath();
80+
ctx.moveTo(Pos1x, Pos1y);
81+
ctx.lineTo(Pos1x + Pos2x, Pos1y + Pos2y);
82+
ctx.stroke();
83+
ctx.closePath();
84+
}
85+
86+
function draw() {
87+
ctx.clearRect(0, 0, canvas.width, canvas.height);
88+
drawBrazo1();
89+
drawBrazo2();
90+
if (rightPressed) {
91+
A1 += 0.01;
92+
}
93+
if (leftPressed) {
94+
A1 -= 0.01;
95+
}
96+
if (upPressed) {
97+
A2 += 0.01;
98+
}
99+
if (downPressed) {
100+
A2 -= 0.01;
101+
}
102+
103+
requestAnimationFrame(draw);
104+
}
105+
draw();
106+
</script>
107+
108+
</body>
109+
110+
</html>

0 commit comments

Comments
 (0)