-
Notifications
You must be signed in to change notification settings - Fork 0
/
kelieedascope.html
122 lines (100 loc) · 3.49 KB
/
kelieedascope.html
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
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Canvas Drawing</title>
<style>
body {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
canvas {
border: 1px solid #ccc;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="400" height="400"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.lineWidth = 10;
ctx.strokeStyle = "#ffffff";
function draw(event) {
if (event.buttons === 1) {
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var x = event.clientX - centerX;
var y = centerY - event.clientY; // Adjusted calculation here
ctx.beginPath();
ctx.moveTo(centerX + x, centerY + y);
ctx.lineTo(centerX - x, centerY + y);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(centerX + x, centerY - y);
ctx.lineTo(centerX - x, centerY - y);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(centerX - x, centerY + y);
ctx.lineTo(centerX - x, centerY - y);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(centerX + x, centerY + y);
ctx.lineTo(centerX + x, centerY - y);
ctx.stroke();
}
}
canvas.addEventListener("mousemove", draw);
function handleKeyPress(event) {
switch(event.key) {
case 'r':
ctx.strokeStyle = "#ff0000"; // red
break;
case 'g':
ctx.strokeStyle = "#00ff00"; // green
break;
case 'b':
ctx.strokeStyle = "#0000ff"; // blue
break;
case 'w':
ctx.strokeStyle = "#ffffff"; // white
break;
case 'e':
ctx.strokeStyle = "#000000"; // black
break;
case 'o':
ctx.strokeStyle = "#ffa500"; // orange
break;
case '/':
ctx.strokeStyle = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`; // random color
break;
case 'p':
ctx.strokeStyle = "#ff00ff"; // purple
break;
case ' ':
ctx.clearRect(0, 0, canvas.width, canvas.height); // clear canvas
break;
case 'a':
ctx.strokeStyle = "#00ffff"; // cyan
break;
case 'y':
ctx.strokeStyle = "#ffff00"; // yellow
break;
case '2':
ctx.lineWidth = 20; // increase stroke width
break;
case '1':
ctx.lineWidth = 10; // default stroke width
break;
}
}
window.addEventListener("keydown", handleKeyPress);
</script>
</body>
</html>