Skip to content

Instantly share code, notes, and snippets.

@horstjens
Created January 16, 2025 15:55
Show Gist options
  • Save horstjens/18a74ff52de1ebc666f3c19218fa2696 to your computer and use it in GitHub Desktop.
Save horstjens/18a74ff52de1ebc666f3c19218fa2696 to your computer and use it in GitHub Desktop.
turtle line diagram
import turtle
# diagramme mit turtle grafik
# französisch-Noten
noten = [2,2,1,5,5,4,2,3,1,1]
# Liniengrafik
WIDTH = 1200
HEIGHT = 800
schulnoten = {
1:"sehr gut",
2:"gut",
3:"befriedigend",
4:"genügend",
5:"nicht genügend",
}
turtle.setup(WIDTH,HEIGHT)
turtle.setworldcoordinates(0,0,WIDTH,HEIGHT)
turtle.title("Annas Französischnoten")
# wir teilen width auf in die anzahl der noten
dx = WIDTH / (len(noten) + 1)
# wir teilen height auf in 5 schulnoten
dy = HEIGHT / (5+1)
turtle.write(str(noten))
turtle.penup()
turtle.pencolor("blue")
turtle.goto(0, dy + 5 * dy - dy * noten[0])
#turtle.pendown()
turtle.pensize(10)
gitter = turtle.Turtle()
gitter.penup()
gitter.goto(0,0)
turtle.tracer(0)
for x in range(0, WIDTH, int(dx)):
gitter.goto(x,0)
gitter.pendown()
gitter.goto(x, HEIGHT)
gitter.penup()
gitter.goto(0,0)
schrift = turtle.Turtle()
schrift.pencolor("#444444") # grau
schrift.penup()
for y in range(0, HEIGHT, int(dy)):
gitter.goto(0, y)
gitter.pendown()
gitter.goto(WIDTH,y)
gitter.penup()
if 5 * dy >= y > 0:
schrift.goto(20,y+5)
schrift.pendown()
note = int(6 - y / dy)
schrift.write(note, font=("System", 20, "normal"))
schrift.penup()
schrift.goto(60,y+5)
schrift.pendown()
schrift.write(schulnoten[note], font=("System",40,"normal"))
schrift.penup()
turtle.tracer(1)
for note in noten:
#turtle.circle(5)
turtle.pencolor("red")
#turtle.write("\u274b", font=("System",32,"normal"))
turtle.pencolor("blue")
x,y = turtle.pos()
y_neu = dy + 5 * dy - dy * note
x_neu = x + dx
turtle.goto(x_neu, y_neu)
turtle.pendown()
turtle.circle(5)
turtle.exitonclick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment