Browse Source

Turtle

main
Oliver Hofmann 4 months ago
parent
commit
96f35476df

BIN
01_Turtle/img/jupyter_started.png View File


BIN
01_Turtle/img/sep.png View File


BIN
01_Turtle/img/start_jupyter_server.png View File


BIN
01_Turtle/img/turtle_comic.png View File


+ 7
- 4
01_Turtle/lesson/01_simple_line.py View File

@@ -1,5 +1,8 @@
from turtle import *
from turtle import Turtle

sophia = Turtle()
sophia.forward(100)

sophia.screen.mainloop()


shape('turtle')
forward(100)
done()

+ 9
- 6
01_Turtle/lesson/02_dotted_line.py View File

@@ -1,9 +1,12 @@
from turtle import *
from turtle import Turtle

sophia = Turtle()
sophia.hideturtle()

for _ in range(10):
penup();
forward(5);
pendown();
forward(5);
sophia.penup()
sophia.forward(5)
sophia.pendown()
sophia.forward(5)

done()
sophia.screen.mainloop()

+ 9
- 5
01_Turtle/lesson/03_colored_line.py View File

@@ -2,15 +2,19 @@ from turtle import *

pensize(5)

pencolor('Green')
pencolor('green')
forward(30)
pencolor('Blue')
pencolor('blue')
forward(30)
pencolor('Red')
pencolor('red')
forward(30)
pencolor('White')
pencolor('white')
forward(30)
pencolor('Black')
pencolor('black')
print(pencolor())
forward(30)
pencolor('#c72426')
forward(30)
print(pencolor())

done()

+ 6
- 4
01_Turtle/lesson/05_square.py View File

@@ -1,10 +1,12 @@
from turtle import *
from turtle import Turtle

sophia = Turtle()

def draw_square():
for _ in range(4):
forward(100)
right(90)
sophia.forward(100)
sophia.right(90)

draw_square()

done()
sophia.screen.mainloop()

+ 8
- 12
01_Turtle/lesson/06_sized_square.py View File

@@ -1,16 +1,12 @@
from turtle import *
from turtle import Turtle

def draw_square(length):
for _ in range(4):
forward(length)
right(90)
sophia = Turtle()

def draw_square(turtle, length):
for _ in range(4):
turtle.forward(length)
turtle.right(90)

draw_square(50)
penup()
forward(100)
pendown()
draw_square(40)
hideturtle()
draw_square(sophia, 100)

done()
sophia.screen.mainloop()

+ 13
- 13
01_Turtle/lesson/07_filled_square.py View File

@@ -1,18 +1,18 @@
from turtle import *
from turtle import Turtle

def draw_square(length):
begin_fill()
def draw_square(turtle, length):
for _ in range(4):
forward(length)
right(90)
end_fill()
turtle.forward(length)
turtle.right(90)

draw_square(50)
penup()
forward(100)
pendown()
draw_square(40)
def draw_filled_square(turtle, length):
turtle.begin_fill()
draw_square(turtle, length)
turtle.end_fill()

hideturtle()

done()
sophia = Turtle()
sophia.fillcolor('red')
draw_filled_square(sophia, 100)

sophia.screen.mainloop()

+ 18
- 0
01_Turtle/lesson/07_filled_square_methods.py View File

@@ -0,0 +1,18 @@
from turtle import Turtle

def draw_square(turtle, length):
for _ in range(4):
turtle.forward(length)
turtle.right(90)

def draw_filled_square(turtle, length):
turtle.begin_fill()
draw_square(turtle, length)
turtle.end_fill()

Turtle.draw_filled_square = draw_filled_square
sophia = Turtle()
sophia.fillcolor('red')
sophia.draw_filled_square(100)

sophia.screen.mainloop()

+ 46
- 0
01_Turtle/projects/ampel.py View File

@@ -0,0 +1,46 @@
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()

+ 40
- 0
01_Turtle/projects/flags.py View File

@@ -0,0 +1,40 @@
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()

+ 19
- 14
01_Turtle/projects/heart.py View File

@@ -1,16 +1,21 @@
from turtle import *
from turtle import Turtle

speed(1)
bgcolor('Black')
pencolor('Red')
fillcolor('Red')
begin_fill()
left(140)
forward(180)
circle(-90, 200)
left(120)
circle(-90, 200)
forward(180)
end_fill()
def draw_heart(turtle):
turtle.left(40)
turtle.forward(178)
turtle.circle(90,200)
turtle.right(120)
turtle.circle(90,200)
turtle.forward(178)

done()

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()

+ 14
- 12
01_Turtle/projects/mandala.py View File

@@ -1,16 +1,18 @@
from turtle import *
from turtle import Turtle

speed(0)
sophia = Turtle()
sophia.speed(0)

for _ in range(36):
pencolor("Blue")
circle(100)
pencolor("Red")
forward(200)
left(120)
color("Orange")
forward(100)
left(70)
forward(15)
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()

done()

+ 11
- 9
01_Turtle/projects/rotating_square.py View File

@@ -1,13 +1,15 @@
from turtle import *
from turtle import Turtle

def draw_square(length):
def draw_square(turtle, length):
for _ in range(4):
forward(length)
right(90)
turtle.forward(length)
turtle.right(90)

def draw_mandala(turtle, length):
for _ in range(18):
draw_square(turtle, length)
turtle.right(20)

for _ in range(18):
draw_square(100)
right(20)

done()
sophia = Turtle()
draw_mandala(sophia, 100)
sophia.screen.mainloop()

+ 25
- 18
01_Turtle/projects/santas_house.py View File

@@ -1,20 +1,27 @@
from turtle import *
import math
from turtle import Turtle

left(90)
forward(100)
right(90)
forward(100)
right(90+45)
forward(141.42)
left(90+45)
forward(100)
left(90+45)
forward(141.42)
right(45+30)
forward(100)
right(120)
forward(100)
right(30)
forward(100)
def draw_santas_house(turtle, length):
turtle.left(90)
turtle.forward(length)
turtle.right(90)
turtle.forward(length)
turtle.right(90 + 45)
turtle.forward(math.sqrt(2*length*length))
turtle.left(90 + 45)
turtle.forward(length)
turtle.left(90 + 45)
turtle.forward(math.sqrt(2*length*length))
turtle.right(45 + 30)
turtle.forward(length)
turtle.right(120)
turtle.forward(length)
turtle.right(30)
turtle.forward(length)

done()


Turtle.draw_santas_house = draw_santas_house
sophia = Turtle()
sophia.draw_santas_house(200)
sophia.screen.mainloop()

+ 50
- 0
01_Turtle/projects/skyscraper.py 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
- 0
01_Turtle/projects/torte.py 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
- 0
01_Turtle/projects/yinyang.py 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
- 0
01_Turtle/projects/zielscheibe.py 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()

Loading…
Cancel
Save