-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturtle.html
More file actions
572 lines (516 loc) · 22.9 KB
/
Copy pathturtle.html
File metadata and controls
572 lines (516 loc) · 22.9 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Python Turtle - Erstelle Grafiken mit der Python Turtle-Bibliothek. Lerne Programmierung durch visuelle Beispiele.">
<meta name="keywords" content="Python, Turtle, Grafik, Programmierung, Informatik, Zeichnen">
<meta name="author" content="Robin Alt">
<meta name="theme-color" content="#0f172a">
<!-- Open Graph / Social Media -->
<meta property="og:title" content="Python Turtle | Informatik with Games">
<meta property="og:description" content="Erstelle atemberaubende Grafiken mit Python Turtle">
<meta property="og:type" content="website">
<meta property="og:image" content="blueCube.jpg">
<!-- Favicon -->
<link rel="icon" type="image/png" href="bot.png">
<!-- Title -->
<title>Python Turtle | Informatik with Games</title>
<!-- Stylesheets -->
<link rel="stylesheet" href="styles.css">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Fira+Code&display=swap" rel="stylesheet">
<!-- Font Awesome für Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
<!-- ============================================
HEADER / NAVIGATION
============================================ -->
<header class="header" id="header">
<div class="nav-container">
<a href="index.html" class="logo">
<img src="bot.png" alt="Informatik with Games Logo">
<span class="logo-text">Informatik with Games</span>
</a>
<div class="nav-toggle" id="navToggle">
<span></span>
<span></span>
<span></span>
</div>
<nav>
<ul class="nav-links" id="navLinks">
<li><a href="index.html">Startseite</a></li>
<li><a href="turtle.html" class="active">Python Turtle</a></li>
<li><a href="Chatbot.html">Chatbot</a></li>
<li><a href="tetris.html">Tetris</a></li>
<li><a href="blackjack.html">Blackjack</a></li>
<li><a href="html.html">HTML</a></li>
<li><a href="info.html">Über mich</a></li>
</ul>
</nav>
</div>
</header>
<!-- ============================================
PAGE HEADER
============================================ -->
<section class="hero" style="min-height: 40vh; padding-top: calc(var(--header-height) + 40px);">
<div class="hero-content">
<h1>Python Turtle</h1>
<p>Erstelle atemberaubende Grafiken und Muster mit der Python Turtle-Bibliothek</p>
</div>
</section>
<!-- ============================================
MAIN CONTENT
============================================ -->
<main class="section">
<div class="container">
<div class="game-container">
<div class="game-header">
<h2 class="game-title">🐢 Python Turtle Grafik</h2>
<p class="game-description">
Die Python Turtle-Bibliothek ist eine einfache Möglichkeit, Grafiken zu erstellen.
Sie ist perfekt für Anfänger, um die Grundlagen der Programmierung zu lernen.
</p>
</div>
<div class="card mb-xl">
<div class="card-header">
<div class="card-icon">
<i class="fas fa-info-circle" style="font-size: 1.5rem; color: var(--primary-color);"></i>
</div>
<h3 class="card-title">Was ist Python Turtle?</h3>
</div>
<div class="card-description">
<p>
Python Turtle ist eine Grafikbibliothek, die es dir ermöglicht, Zeichnungen
durch Programmierung zu erstellen. Die "Turtle" (Schildkröte) ist ein Cursor,
der sich auf dem Bildschirm bewegt und Linien zieht.
</p>
<p>
<strong>Grundlegende Befehle:</strong>
</p>
<div class="card-tags">
<span class="tag"><code>forward(100)</code> - Bewege dich vorwärts</span>
<span class="tag"><code>backward(100)</code> - Bewege dich rückwärts</span>
<span class="tag"><code>left(90)</code> - Drehe nach links</span>
<span class="tag"><code>right(90)</code> - Drehe nach rechts</span>
<span class="tag"><code>penup()</code> - Hebe den Stift</span>
<span class="tag"><code>pendown()</code> - Senke den Stift</span>
</div>
</div>
</div>
<!-- Turtle Canvas Area -->
<div class="card mb-xl">
<div class="card-header">
<div class="card-icon">
<i class="fas fa-paint-brush" style="font-size: 1.5rem; color: var(--secondary-color);"></i>
</div>
<h3 class="card-title">Zeichenfläche</h3>
</div>
<div style="text-align: center;">
<canvas id="turtleCanvas"
style="background: var(--bg-tertiary); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);">
Dein Browser unterstützt kein HTML5 Canvas. Bitte aktualisiere deinen Browser.
</canvas>
</div>
<div class="game-controls mt-lg">
<button class="btn btn-primary" onclick="drawSquare()">
<i class="fas fa-square"></i> Quadrat zeichnen
</button>
<button class="btn btn-primary" onclick="drawCircle()">
<i class="fas fa-circle"></i> Kreis zeichnen
</button>
<button class="btn btn-primary" onclick="drawStar()">
<i class="fas fa-star"></i> Stern zeichnen
</button>
<button class="btn btn-secondary" onclick="clearCanvas()">
<i class="fas fa-trash"></i> Löschen
</button>
</div>
</div>
<!-- Code Editor Section -->
<div class="card mb-xl">
<div class="card-header">
<div class="card-icon">
<i class="fas fa-code" style="font-size: 1.5rem; color: var(--accent-color);"></i>
</div>
<h3 class="card-title">Eigener Code</h3>
</div>
<div class="card-description">
<p>
Schreibe deinen eigenen Turtle-Code und sieh das Ergebnis sofort!
</p>
<div class="code-block">
<div class="code-header">
<span class="code-title">turtle_code.py</span>
<button class="code-copy" onclick="copyTurtleCode()">
<i class="fas fa-copy"></i> Kopieren
</button>
<button class="btn btn-accent" onclick="runTurtleCode()" style="margin-left: var(--spacing-sm);">
<i class="fas fa-play"></i> Ausführen
</button>
</div>
<div class="code-content">
<textarea id="turtleCode"
style="width: 100%; min-height: 150px; background: transparent; border: none; color: var(--text-primary); font-family: var(--font-mono); font-size: 0.9rem; resize: vertical; outline: none;"
placeholder="# Schreibe deinen Turtle-Code hier...
# Beispiel:
forward(100)
left(90)
forward(100)
left(90)
forward(100)
left(90)
forward(100)
"># Schreibe deinen Turtle-Code hier...
# Beispiel:
forward(100)
left(90)
forward(100)
left(90)
forward(100)
left(90)
forward(100)</textarea>
</div>
</div>
</div>
</div>
<!-- Examples Section -->
<div class="card mb-xl">
<div class="card-header">
<div class="card-icon">
<i class="fas fa-lightbulb" style="font-size: 1.5rem; color: var(--primary-color);"></i>
</div>
<h3 class="card-title">Beispiele</h3>
</div>
<div class="card-description">
<p>
Hier sind einige Code-Beispiele, die du ausprobieren kannst:
</p>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: var(--spacing-lg); margin-top: var(--spacing-lg);">
<div class="card" style="cursor: pointer;" onclick="loadExample('square')">
<h4>Quadrat</h4>
<code>forward(100)<br>left(90)<br>forward(100)<br>left(90)<br>forward(100)<br>left(90)<br>forward(100)</code>
</div>
<div class="card" style="cursor: pointer;" onclick="loadExample('spiral')">
<h4>Spirale</h4>
<code>for i in range(100):<br> forward(i)<br> left(91)</code>
</div>
<div class="card" style="cursor: pointer;" onclick="loadExample('star')">
<h4>Stern</h4>
<code>for i in range(5):<br> forward(100)<br> right(144)</code>
</div>
<div class="card" style="cursor: pointer;" onclick="loadExample('circle')">
<h4>Kreis</h4>
<code>circle(50)</code>
</div>
</div>
</div>
</div>
<div class="text-center mt-xl">
<a href="index.html" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Zurück zur Startseite
</a>
</div>
</div>
</div>
</main>
<!-- ============================================
FOOTER
============================================ -->
<footer class="footer">
<div class="container">
<div class="footer-content">
<div class="footer-section">
<h3>Navigation</h3>
<ul>
<li><a href="index.html">Startseite</a></li>
<li><a href="turtle.html">Python Turtle</a></li>
<li><a href="Chatbot.html">Chatbot</a></li>
<li><a href="tetris.html">Tetris</a></li>
<li><a href="html.html">HTML</a></li>
<li><a href="info.html">Über mich</a></li>
</ul>
</div>
<div class="footer-section">
<h3>Projekte</h3>
<ul>
<li><a href="turtle.html">Turtle Grafik</a></li>
<li><a href="Chatbot.html">KI Chatbot</a></li>
<li><a href="tetris.html">Tetris Spiel</a></li>
<li><a href="blackjack.html">Blackjack</a></li>
<li><a href="html.html">HTML Lernen</a></li>
</ul>
</div>
<div class="footer-section">
<h3>Technologien</h3>
<ul>
<li><a href="#">Python</a></li>
<li><a href="#">Turtle</a></li>
<li><a href="#">HTML5 Canvas</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</div>
<div class="footer-section">
<h3>Spiele</h3>
<ul>
<li><a href="tetris.html">Tetris</a></li>
<li><a href="blackjack.html">Blackjack</a></li>
</ul>
</div>
</div>
<div class="footer-bottom">
<p>© 2024 Informatik with Games. Alle Rechte vorbehalten.</p>
</div>
</div>
</footer>
<!-- ============================================
SCRIPTS
============================================ -->
<script src="init.js"></script>
<script>
// Mobile Navigation Toggle
const navToggle = document.getElementById('navToggle');
const navLinks = document.getElementById('navLinks');
const header = document.getElementById('header');
navToggle.addEventListener('click', () => {
navToggle.classList.toggle('active');
navLinks.classList.toggle('active');
});
document.querySelectorAll('.nav-links a').forEach(link => {
link.addEventListener('click', () => {
navToggle.classList.remove('active');
navLinks.classList.remove('active');
});
});
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
document.querySelectorAll('.nav-links a').forEach(link => {
if (link.href === window.location.href) {
link.classList.add('active');
}
});
// Turtle Graphics Implementation
const canvas = document.getElementById('turtleCanvas');
const ctx = canvas.getContext('2d');
// Set canvas size
canvas.width = 600;
canvas.height = 400;
// Turtle state
let turtle = {
x: canvas.width / 2,
y: canvas.height / 2,
angle: 0,
penDown: true,
color: '#00d4aa',
width: 2
};
// Initialize canvas
function initCanvas() {
ctx.fillStyle = '#334155';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = turtle.color;
ctx.lineWidth = turtle.width;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
}
// Clear canvas
function clearCanvas() {
initCanvas();
turtle.x = canvas.width / 2;
turtle.y = canvas.height / 2;
turtle.angle = 0;
}
// Move turtle forward
function forward(distance) {
const rad = turtle.angle * Math.PI / 180;
const newX = turtle.x + distance * Math.cos(rad);
const newY = turtle.y - distance * Math.sin(rad);
if (turtle.penDown) {
ctx.beginPath();
ctx.moveTo(turtle.x, turtle.y);
ctx.lineTo(newX, newY);
ctx.stroke();
}
turtle.x = newX;
turtle.y = newY;
}
// Move turtle backward
function backward(distance) {
forward(-distance);
}
// Turn turtle left
function left(angle) {
turtle.angle -= angle;
}
// Turn turtle right
function right(angle) {
turtle.angle += angle;
}
// Lift pen
function penup() {
turtle.penDown = false;
}
// Put pen down
function pendown() {
turtle.penDown = true;
}
// Set color
function color(col) {
turtle.color = col;
ctx.strokeStyle = col;
}
// Set width
function width(w) {
turtle.width = w;
ctx.lineWidth = w;
}
// Draw a square
function drawSquare() {
clearCanvas();
for (let i = 0; i < 4; i++) {
forward(100);
left(90);
}
}
// Draw a circle
function drawCircle() {
clearCanvas();
ctx.beginPath();
ctx.arc(canvas.width / 2, canvas.height / 2, 50, 0, 2 * Math.PI);
ctx.stroke();
}
// Draw a star
function drawStar() {
clearCanvas();
for (let i = 0; i < 5; i++) {
forward(100);
right(144);
}
}
// Draw a spiral
function drawSpiral() {
clearCanvas();
for (let i = 0; i < 100; i++) {
forward(i);
left(91);
}
}
// Execute turtle code
function runTurtleCode() {
const code = document.getElementById('turtleCode').value;
clearCanvas();
try {
// Simple parser for turtle commands
const lines = code.split('\n');
lines.forEach(line => {
const trimmed = line.trim();
if (trimmed && !trimmed.startsWith('#')) {
const match = trimmed.match(/^(\w+)\(([^)]*)\)/);
if (match) {
const command = match[1].toLowerCase();
const args = match[2].split(',').map(arg => parseFloat(arg.trim()) || arg.trim().replace(/['"]/g, ''));
switch(command) {
case 'forward':
case 'fd':
forward(args[0] || 100);
break;
case 'backward':
case 'bk':
backward(args[0] || 100);
break;
case 'left':
case 'lt':
left(args[0] || 90);
break;
case 'right':
case 'rt':
right(args[0] || 90);
break;
case 'penup':
case 'pu':
penup();
break;
case 'pendown':
case 'pd':
pendown();
break;
case 'color':
color(args[0] || '#00d4aa');
break;
case 'width':
width(args[0] || 2);
break;
case 'circle':
const radius = args[0] || 50;
ctx.beginPath();
ctx.arc(turtle.x, turtle.y - radius, radius, Math.PI / 2, Math.PI * 2.5);
ctx.stroke();
turtle.x += radius;
break;
}
}
}
});
} catch (e) {
alert('Fehler im Code: ' + e.message);
}
}
// Load example code
function loadExample(type) {
const codeArea = document.getElementById('turtleCode');
let code = '';
switch(type) {
case 'square':
code = '# Quadrat zeichnen\nforward(100)\nleft(90)\nforward(100)\nleft(90)\nforward(100)\nleft(90)\nforward(100)';
break;
case 'spiral':
code = '# Spirale zeichnen\nfor i in range(100):\n forward(i)\n left(91)';
break;
case 'star':
code = '# Stern zeichnen\nfor i in range(5):\n forward(100)\n right(144)';
break;
case 'circle':
code = '# Kreis zeichnen\ncircle(50)';
break;
}
codeArea.value = code;
}
// Copy code
function copyTurtleCode() {
const code = document.getElementById('turtleCode').value;
navigator.clipboard.writeText(code).then(() => {
alert('Code wurde in die Zwischenablage kopiert!');
});
}
// Initialize
initCanvas();
// Add animation on scroll
const animateOnScroll = () => {
const elements = document.querySelectorAll('.card, .game-container');
elements.forEach(element => {
const elementPosition = element.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (elementPosition < windowHeight - 100) {
element.style.opacity = '1';
element.style.transform = 'translateY(0)';
}
});
};
document.querySelectorAll('.card, .game-container').forEach(element => {
element.style.opacity = '0';
element.style.transform = 'translateY(20px)';
element.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
});
window.addEventListener('scroll', animateOnScroll);
window.addEventListener('load', animateOnScroll);
</script>
</body>
</html>