Zum Hauptinhalt springen

Das Haus vom Nikolaus

Die Schildkröte (Turtle aus der TKinter Bibliothek) erlaubt einfache bis komplexe Grafiken mittels Python auf den Bildschirm zu bringen. Sie wird mit verständlichen Befehlen wie forward, left, right, usw. gesteuert. Ältere Programmierer kennen sie bereits aus Logo (1976), COMAL (1973), etc. - jüngere Programmierer kennen vergleichbares von Scratch (2007) mit dem sogenannten “Malstift”.

Nikolaus
flowchart TD
    A[Start] --> B[Initialisiere Turtle und Fenster]
    B --> C[Setze Hausparameter a, x, y]
    C --> D[Setze Turtle-Einstellungen Form, Geschwindigkeit, Stiftdicke]
    D --> E[Zeichne Grundfläche: teleportiere zu x, y]
    E --> F[Zeichne Linie zu x+a, y]
    F --> G[Zeichne Linie zu x, y+a]
    G --> H[Zeichne Linie zu x+a, y+a]
    H --> I[Zeichne Linie zurück zu x, y]
    I --> J[Zeichne Linie zu x, y+a]
    J --> K[Zeichne Dachspitze: zu x+a/2, y+a+a/2]
    K --> L[Zeichne Linie zu x+a, y+a]
    L --> M[Zeichne Linie zu x+a, y]
    M --> N[Blende Turtle aus]
    N --> O[Programmende]
# https://docs.python.org/3.13/library/turtle.html
import turtle  # Bestandteil von tkinter

# Hausparameter
a = 100  # Seitenlänge der Grundfläche in Pixel
# Startposition (unten links)
x, y = 0 - a/2, 0 - a/2  # 0,0 entspricht Mitte des Fensters

# Fenster einrichten
turtle.title("Das Haus vom Nikolaus")
turtle.setup(a * 3, a * 3)  # Fensterbreite, Fensterhöhe in Pixel
turtle.shape("turtle")  # arrow, circle, ...
turtle.speed(3)  # 0 = sofort, 1 - 10 sehr schnell => help(turtle.speed)
turtle.pensize(3)

# Zeichnen
# turtle.penup()
# turtle.goto(x, y)
# turtle.pendown()
turtle.teleport(x, y)
turtle.goto(x + a, y)
turtle.goto(x, y + a)
turtle.goto(x + a, y + a)
turtle.goto(x, y)
turtle.goto(x, y + a)
turtle.goto(x + a / 2, y + a + a / 2)
turtle.goto(x + a, y + a)
turtle.goto(x + a, y)

# Programmende
turtle.hideturtle()
turtle.done()