217 lines
8.7 KiB
HTML
217 lines
8.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
|
<title>Malen - KinderWelt</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }
|
|
body {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh; display: flex; flex-direction: column; align-items: center;
|
|
font-family: 'Comic Sans MS', cursive, sans-serif; padding: 10px;
|
|
}
|
|
h1 { color: white; margin: 10px 0; font-size: 24px; }
|
|
.canvas-container {
|
|
background: white; border-radius: 10px; padding: 10px;
|
|
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
|
}
|
|
#paintCanvas {
|
|
background: white; border: 2px solid #ddd; border-radius: 5px;
|
|
cursor: crosshair; touch-action: none;
|
|
}
|
|
.tools {
|
|
display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
|
|
margin: 15px 0; max-width: 600px;
|
|
}
|
|
.color-btn {
|
|
width: 50px; height: 50px; border: 3px solid white; border-radius: 50%;
|
|
cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
|
transition: transform 0.2s;
|
|
}
|
|
.color-btn:hover { transform: scale(1.1); }
|
|
.color-btn.active {
|
|
box-shadow: 0 0 0 4px #4ade80, 0 2px 5px rgba(0,0,0,0.2);
|
|
transform: scale(1.15);
|
|
}
|
|
.size-slider {
|
|
-webkit-appearance: none; width: 150px; height: 10px;
|
|
background: rgba(255,255,255,0.3); border-radius: 5px; outline: none;
|
|
}
|
|
.size-slider::-webkit-slider-thumb {
|
|
-webkit-appearance: none; width: 25px; height: 25px; background: white;
|
|
border-radius: 50%; cursor: pointer;
|
|
}
|
|
.tool-btn {
|
|
background: white; border: none; border-radius: 10px;
|
|
padding: 10px 20px; font-size: 20px; cursor: pointer;
|
|
}
|
|
.tool-btn.active { background: #4ade80; }
|
|
.controls { display: flex; gap: 15px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
|
|
.btn {
|
|
background: linear-gradient(135deg, #4ade80, #22c55e); border: none; border-radius: 10px;
|
|
padding: 12px 25px; font-size: 16px; cursor: pointer; font-family: inherit; font-weight: bold;
|
|
color: white;
|
|
}
|
|
.btn-back { background: #ff6b6b; text-decoration: none; }
|
|
.btn-clear { background: #feca57; }
|
|
.size-label { color: white; font-size: 14px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>🎨 Malen</h1>
|
|
|
|
<div class="canvas-container">
|
|
<canvas id="paintCanvas" width="600" height="400"></canvas>
|
|
</div>
|
|
|
|
<div class="tools">
|
|
<button class="color-btn active" style="background: #000000;" onclick="setColor('#000000')" title="Schwarz"></button>
|
|
<button class="color-btn" style="background: #ff0000;" onclick="setColor('#ff0000')" title="Rot"></button>
|
|
<button class="color-btn" style="background: #00ff00;" onclick="setColor('#00ff00')" title="Grün"></button>
|
|
<button class="color-btn" style="background: #0000ff;" onclick="setColor('#0000ff')" title="Blau"></button>
|
|
<button class="color-btn" style="background: #ffff00;" onclick="setColor('#ffff00')" title="Gelb"></button>
|
|
<button class="color-btn" style="background: #ff00ff;" onclick="setColor('#ff00ff')" title="Magenta"></button>
|
|
<button class="color-btn" style="background: #00ffff;" onclick="setColor('#00ffff')" title="Cyan"></button>
|
|
<button class="color-btn" style="background: #ffa500;" onclick="setColor('#ffa500')" title="Orange"></button>
|
|
<button class="color-btn" style="background: #800080;" onclick="setColor('#800080')" title="Lila"></button>
|
|
<button class="color-btn" style="background: #ffffff; border: 2px solid #ccc;" onclick="setColor('#ffffff')" title="Weiß"></button>
|
|
</div>
|
|
|
|
<div style="display: flex; align-items: center; gap: 15px; flex-wrap: wrap; justify-content: center;">
|
|
<div class="size-label">Pinselgröße:</div>
|
|
<input type="range" class="size-slider" id="brushSize" min="1" max="50" value="5">
|
|
<button class="tool-btn active" id="brushBtn" onclick="setTool('brush')">🖌️ Pinsel</button>
|
|
<button class="tool-btn" id="eraserBtn" onclick="setTool('eraser')">🧹 Radiergummi</button>
|
|
</div>
|
|
|
|
<div class="controls">
|
|
<button class="btn btn-clear" onclick="clearCanvas()">🗑️ Alles löschen</button>
|
|
<button class="btn" onclick="saveImage()">💾 Speichern</button>
|
|
<a href="../index.html" class="btn btn-back">⬅️ Zurück</a>
|
|
</div>
|
|
|
|
<script>
|
|
const canvas = document.getElementById('paintCanvas');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
// Responsive canvas
|
|
function resizeCanvas() {
|
|
const maxWidth = Math.min(window.innerWidth - 40, 800);
|
|
const scale = maxWidth / 600;
|
|
canvas.style.width = maxWidth + 'px';
|
|
canvas.style.height = (400 * scale) + 'px';
|
|
}
|
|
resizeCanvas();
|
|
window.addEventListener('resize', resizeCanvas);
|
|
|
|
// Drawing state
|
|
let isDrawing = false;
|
|
let currentColor = '#000000';
|
|
let currentSize = 5;
|
|
let currentTool = 'brush';
|
|
let lastX = 0;
|
|
let lastY = 0;
|
|
|
|
// Set canvas background to white
|
|
ctx.fillStyle = '#ffffff';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
function getMousePos(e) {
|
|
const rect = canvas.getBoundingClientRect();
|
|
const scaleX = canvas.width / rect.width;
|
|
const scaleY = canvas.height / rect.height;
|
|
|
|
if (e.touches) {
|
|
return {
|
|
x: (e.touches[0].clientX - rect.left) * scaleX,
|
|
y: (e.touches[0].clientY - rect.top) * scaleY
|
|
};
|
|
}
|
|
return {
|
|
x: (e.clientX - rect.left) * scaleX,
|
|
y: (e.clientY - rect.top) * scaleY
|
|
};
|
|
}
|
|
|
|
function startDrawing(e) {
|
|
isDrawing = true;
|
|
const pos = getMousePos(e);
|
|
lastX = pos.x;
|
|
lastY = pos.y;
|
|
e.preventDefault();
|
|
}
|
|
|
|
function draw(e) {
|
|
if (!isDrawing) return;
|
|
|
|
const pos = getMousePos(e);
|
|
|
|
ctx.beginPath();
|
|
ctx.moveTo(lastX, lastY);
|
|
ctx.lineTo(pos.x, pos.y);
|
|
ctx.lineCap = 'round';
|
|
ctx.lineJoin = 'round';
|
|
ctx.lineWidth = currentSize;
|
|
|
|
if (currentTool === 'eraser') {
|
|
ctx.strokeStyle = '#ffffff';
|
|
} else {
|
|
ctx.strokeStyle = currentColor;
|
|
}
|
|
|
|
ctx.stroke();
|
|
|
|
lastX = pos.x;
|
|
lastY = pos.y;
|
|
e.preventDefault();
|
|
}
|
|
|
|
function stopDrawing() {
|
|
isDrawing = false;
|
|
}
|
|
|
|
// Event listeners
|
|
canvas.addEventListener('mousedown', startDrawing);
|
|
canvas.addEventListener('mousemove', draw);
|
|
canvas.addEventListener('mouseup', stopDrawing);
|
|
canvas.addEventListener('mouseout', stopDrawing);
|
|
|
|
canvas.addEventListener('touchstart', startDrawing);
|
|
canvas.addEventListener('touchmove', draw);
|
|
canvas.addEventListener('touchend', stopDrawing);
|
|
|
|
// Tools
|
|
function setColor(color) {
|
|
currentColor = color;
|
|
document.querySelectorAll('.color-btn').forEach(btn => btn.classList.remove('active'));
|
|
event.target.classList.add('active');
|
|
setTool('brush');
|
|
}
|
|
|
|
function setTool(tool) {
|
|
currentTool = tool;
|
|
document.getElementById('brushBtn').classList.toggle('active', tool === 'brush');
|
|
document.getElementById('eraserBtn').classList.toggle('active', tool === 'eraser');
|
|
}
|
|
|
|
document.getElementById('brushSize').addEventListener('input', (e) => {
|
|
currentSize = e.target.value;
|
|
});
|
|
|
|
function clearCanvas() {
|
|
if (confirm('Möchtest du wirklich alles löschen?')) {
|
|
ctx.fillStyle = '#ffffff';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
}
|
|
}
|
|
|
|
function saveImage() {
|
|
const link = document.createElement('a');
|
|
link.download = 'malerei-' + new Date().toISOString().slice(0, 10) + '.png';
|
|
link.href = canvas.toDataURL();
|
|
link.click();
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |