-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
150 lines (138 loc) · 4.96 KB
/
index.html
File metadata and controls
150 lines (138 loc) · 4.96 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zeichenfläche</title>
<style>
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css');
body {
margin: 0;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
touch-action: none;
}
.toolbar {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 15px;
background: rgba(255, 255, 255, 0.95);
padding: 12px 20px;
border-radius: 12px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(10px);
z-index: 1000;
}
.toolbar button, .toolbar input {
background: none;
border: none;
cursor: pointer;
font-size: 24px;
color: #333;
transition: transform 0.2s ease;
}
.toolbar button:hover {
transform: scale(1.1);
}
.toolbar input[type="color"] {
width: 30px;
height: 30px;
border: none;
padding: 0;
cursor: pointer;
}
.toolbar input[type="range"] {
width: 100px;
}
canvas {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: repeating-linear-gradient(
0deg, #ccc, #ccc 1px, transparent 1px, transparent 20px),
repeating-linear-gradient(
90deg, #ccc, #ccc 1px, transparent 1px, transparent 20px);
cursor: crosshair;
z-index: 1;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body>
<div class="toolbar">
<input type="color" id="colorPicker" value="#000000" onchange="changeColor()">
<button id="colorButton" title="Farbe wählen"><i class="fa-solid fa-palette"></i></button>
<button id="clearButton" title="Leeren"><i class="fa-solid fa-trash"></i></button>
<button id="eraserButton" title="Radierer"><i class="fa-solid fa-eraser"></i></button>
<input type="range" id="brushSize" min="1" max="20" value="3" onchange="changeBrushSize()">
</div>
<canvas id="canvas"></canvas>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let painting = false;
let erasing = false;
let currentColor = "#000000";
let lineWidth = 3;
let eraserSize = 20;
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resizeCanvas();
window.addEventListener('resize', resizeCanvas);
function startPosition(e) {
if (e.target.closest('.toolbar')) return;
painting = true;
draw(e);
}
function stopPosition() {
painting = false;
ctx.beginPath();
}
function draw(e) {
if (!painting) return;
const x = e.clientX || e.touches[0].clientX;
const y = e.clientY || e.touches[0].clientY;
ctx.lineWidth = erasing ? eraserSize : lineWidth;
ctx.lineCap = 'round';
ctx.strokeStyle = erasing ? '#f0f0f0' : currentColor;
ctx.lineTo(x, y);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(x, y);
}
function changeColor() {
currentColor = document.getElementById('colorPicker').value;
erasing = false;
}
function toggleEraser() {
erasing = !erasing;
}
function clearCanvas() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
function changeBrushSize() {
lineWidth = document.getElementById('brushSize').value;
}
document.getElementById('colorButton').addEventListener('click', changeColor);
document.getElementById('eraserButton').addEventListener('click', toggleEraser);
document.getElementById('clearButton').addEventListener('click', clearCanvas);
canvas.addEventListener('mousedown', startPosition);
canvas.addEventListener('mouseup', stopPosition);
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('touchstart', (e) => { e.preventDefault(); startPosition(e); });
canvas.addEventListener('touchend', stopPosition);
canvas.addEventListener('touchmove', (e) => { e.preventDefault(); draw(e); });
</script>
</body>
</html>