This commit is contained in:
Oliver Hofmann
2024-09-23 13:22:12 +02:00
commit 45c4160142
69 changed files with 1906 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
# Zeichnen einer Ampel
from turtle import Turtle
def draw_rectangle(turtle, width, height):
for _ in range(2):
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
def draw_case(turtle):
turtle.pencolor('black')
turtle.fillcolor('black')
turtle.pendown()
turtle.begin_fill()
draw_rectangle(turtle, 70, 190)
turtle.end_fill()
turtle.penup()
def draw_light(turtle, color):
turtle.pencolor(color)
turtle.fillcolor(color)
turtle.pendown()
turtle.begin_fill()
turtle.right(90)
turtle.circle(25)
turtle.end_fill()
turtle.penup()
turtle.left(90)
def draw_traffic_light(turtle):
draw_case(turtle)
turtle.forward(35)
turtle.left(90)
turtle.forward(10)
draw_light(turtle, 'green')
turtle.forward(60)
draw_light(turtle, 'yellow')
turtle.forward(60)
draw_light(turtle, 'red')
zoe = Turtle()
draw_traffic_light(zoe)
zoe.hideturtle()
zoe.screen.mainloop()
+41
View File
@@ -0,0 +1,41 @@
# Zeichnen von Flaggen mit der Turtle
from turtle import Turtle
def draw_flag(turtle, color1, color2, color3):
turtle.pencolor('black')
turtle.pendown()
draw_rectangle(turtle, 600, 300)
turtle.penup()
draw_segment(turtle, color1)
draw_segment(turtle, color2)
draw_segment(turtle, color3)
def draw_segment(turtle, color):
turtle.fillcolor(color)
draw_filled_rectangle(turtle, 200, 300)
turtle.forward(200)
def draw_filled_rectangle(turtle, width, height):
turtle.begin_fill()
draw_rectangle(turtle, width, height)
turtle.end_fill()
def draw_rectangle(turtle, width, height):
for _ in range(2):
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
Turtle.draw_flag = draw_flag
sophia = Turtle()
sophia.draw_flag('green', 'white', 'red')
sophia.backward(600)
sophia.right(90)
sophia.forward(400)
sophia.left(90)
sophia.draw_flag('blue', 'white', 'red')
sophia.hideturtle()
sophia.screen.mainloop()
+36
View File
@@ -0,0 +1,36 @@
# Zeichnen der Flagge Deutschlands mit der Turtle
from turtle import *
def draw_rectangle(width, height):
begin_fill()
forward(width)
right(90)
forward(height)
right(90)
forward(width)
right(90)
forward(height)
right(90)
end_fill()
def next_shape():
penup()
right(90)
forward(50)
left(90)
pendown()
pencolor('Black')
fillcolor('Black')
draw_rectangle(200, 50)
next_shape()
pencolor('Red')
fillcolor('Red')
draw_rectangle(200,50)
next_shape()
pencolor('Yellow')
fillcolor('Yellow')
draw_rectangle(200,50)
done()
+22
View File
@@ -0,0 +1,22 @@
# Zeichnen
from turtle import Turtle
def draw_heart(turtle):
turtle.left(40)
turtle.forward(178)
turtle.circle(90,200)
turtle.right(120)
turtle.circle(90,200)
turtle.forward(178)
sophia = Turtle()
sophia.screen.bgcolor('Black')
sophia.pencolor('Red')
sophia.fillcolor('Red')
sophia.begin_fill()
draw_heart(sophia)
sophia.end_fill()
sophia.hideturtle()
sophia.screen.mainloop()
+66
View File
@@ -0,0 +1,66 @@
# Zeichnen des Wortes "Hello" mit der Turtle
from turtle import Turtle
def space(turtle):
turtle.penup()
turtle.forward(30)
turtle.pendown()
def draw_h(turtle):
turtle.left(90)
turtle.forward(100)
turtle.backward(50)
turtle.right(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.backward(100)
turtle.right(90)
def draw_e(turtle):
turtle.left(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.backward(50)
turtle.right(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(30)
turtle.backward(30)
turtle.right(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
def draw_l(turtle):
turtle.left(90)
turtle.forward(100)
turtle.backward(100)
turtle.right(90)
turtle.forward(50)
def draw_o(turtle):
turtle.penup()
turtle.forward(40)
turtle.pendown()
turtle.circle(50)
turtle.penup()
turtle.forward(40)
turtle.pendown()
sophia = Turtle()
sophia.speed(0)
draw_h(sophia)
space(sophia)
draw_e(sophia)
space(sophia)
draw_l(sophia)
space(sophia)
draw_l(sophia)
space(sophia)
draw_o(sophia)
sophia.screen.mainloop()
+20
View File
@@ -0,0 +1,20 @@
# Zeichnet ein Mandala mit der Turtle-Grafik
from turtle import Turtle
sophia = Turtle()
sophia.speed(0)
for _ in range(36):
sophia.pencolor("Blue")
sophia.circle(100)
sophia.pencolor("Red")
sophia.forward(200)
sophia.left(120)
sophia.color("Orange")
sophia.forward(100)
sophia.left(70)
sophia.forward(15)
sophia.screen.mainloop()
+15
View File
@@ -0,0 +1,15 @@
from turtle import Turtle
def draw_square(turtle, length):
for _ in range(4):
turtle.forward(length)
turtle.right(90)
def draw_mandala(turtle, length):
for _ in range(18):
draw_square(turtle, length)
turtle.right(20)
sophia = Turtle()
draw_mandala(sophia, 100)
sophia.screen.mainloop()
+27
View File
@@ -0,0 +1,27 @@
import math
from turtle import Turtle
def draw_santas_house(turtle, length):
turtle.left(90)
turtle.forward(length)
turtle.right(90)
turtle.forward(length)
turtle.right(90 + 45)
turtle.forward(1.4142 * length)
turtle.left(90 + 45)
turtle.forward(length)
turtle.left(90 + 45)
turtle.forward(1.4142 * length)
turtle.right(45 + 30)
turtle.forward(length)
turtle.right(120)
turtle.forward(length)
turtle.right(30)
turtle.forward(length)
Turtle.draw_santas_house = draw_santas_house
sophia = Turtle()
sophia.draw_santas_house(200)
sophia.screen.mainloop()
+50
View File
@@ -0,0 +1,50 @@
from turtle import Turtle
def draw_building(turtle):
turtle.fillcolor('black')
turtle.pencolor('black')
draw_filled_rectangle(turtle,100, 210)
turtle.left(90)
for _ in range(5):
draw_floor(turtle)
def draw_floor(turtle):
turtle.penup()
turtle.forward(10)
turtle.right(90)
turtle.forward(10)
turtle.pendown()
for _ in range(3):
draw_window(turtle)
next_window(turtle)
turtle.penup()
turtle.backward(100)
turtle.left(90)
turtle.forward(30)
def draw_window(turtle):
turtle.fillcolor('yellow')
turtle.pencolor('yellow')
draw_filled_rectangle(turtle, 20, 30)
def next_window(turtle):
turtle.penup()
turtle.forward(30)
turtle.pendown()
def draw_filled_rectangle(turtle, width, height):
turtle.begin_fill()
for _ in range(2):
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
turtle.end_fill()
sophia = Turtle()
sophia.screen.bgcolor('blue')
draw_building(sophia)
sophia.hideturtle()
sophia.screen.mainloop()
+31
View File
@@ -0,0 +1,31 @@
from turtle import Turtle
def draw_segment(turtle, degree, length):
turtle.pendown()
turtle.begin_fill()
turtle.circle(length, degree)
turtle.left(90)
turtle.forward(length)
turtle.right(degree)
turtle.backward(length)
turtle.end_fill()
turtle.penup()
turtle.forward(length)
turtle.left(degree)
turtle.backward(length)
turtle.right(90)
Turtle.draw_segment = draw_segment
sophia = Turtle()
sophia.pencolor('red')
sophia.fillcolor('red')
sophia.draw_segment(240, 100)
sophia.pencolor('blue')
sophia.fillcolor('blue')
sophia.draw_segment(90, 100)
sophia.pencolor('green')
sophia.fillcolor('green')
sophia.draw_segment(30, 100)
sophia.hideturtle()
sophia.screen.mainloop()
+70
View File
@@ -0,0 +1,70 @@
from turtle import Turtle
sophia = Turtle()
zoe = Turtle()
sophia.screen.bgcolor('grey')
sophia.pencolor('black')
sophia.fillcolor('black')
zoe.pencolor('white')
zoe.fillcolor('white')
zoe.begin_fill()
zoe.left(90)
zoe.penup()
zoe.forward(300)
zoe.left(90)
zoe.circle(150, 180)
zoe.end_fill()
sophia.begin_fill()
sophia.circle(150, 180)
sophia.penup()
sophia.left(90)
sophia.forward(300)
sophia.left(90)
sophia.end_fill()
zoe.penup()
zoe.left(90)
zoe.forward(150)
zoe.right(90)
zoe.pendown()
zoe.begin_fill()
zoe.circle(75,180)
zoe.left(90)
zoe.forward(150)
zoe.end_fill()
sophia.pendown()
sophia.begin_fill()
sophia.left(90)
sophia.forward(150)
sophia.left(90)
sophia.circle(75,180)
sophia.end_fill()
zoe.penup()
zoe.forward(85)
zoe.left(90)
zoe.pendown()
zoe.begin_fill()
zoe.circle(10)
zoe.end_fill()
sophia.penup()
sophia.left(90)
sophia.forward(235)
sophia.left(90)
sophia.pendown()
sophia.begin_fill()
sophia.circle(10)
sophia.end_fill()
sophia.hideturtle()
zoe.hideturtle()
sophia.screen.mainloop()
+26
View File
@@ -0,0 +1,26 @@
from turtle import Turtle
def draw_archery_target(turtle):
draw_circle(turtle, 30, 'red')
draw_circle(turtle, 20, 'white')
draw_circle(turtle, 10, 'red')
def draw_circle(turtle, radius, color):
turtle.fillcolor(color)
turtle.pencolor(color)
turtle.begin_fill()
turtle.pendown()
turtle.circle(radius)
turtle.penup()
turtle.end_fill()
turtle.left(90)
turtle.forward(10)
turtle.right(90)
sophia = Turtle()
draw_archery_target(sophia)
sophia.hideturtle()
sophia.screen.mainloop()