Skip to content

Instantly share code, notes, and snippets.

@spheppner
Created June 29, 2016 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spheppner/de70ae9ed8f66d5bec4c022d7f6f0629 to your computer and use it in GitHub Desktop.
Save spheppner/de70ae9ed8f66d5bec4c022d7f6f0629 to your computer and use it in GitHub Desktop.
Turtle-Kanone
import easygui as e
import math
import random as r
import turtle as t
def castle(l=600):
t.begin_fill()
t.fd(l) # unterseite
t.lt(90)
t.fd(2 * l / 3) #turm rechts oben
t.lt(45) # schräges dach rechte seite von rechtem turm
t.fd( (l /3) * 1/2**0.5 ) # länge vom schrägen dach
t.lt(90)
t.fd( l /3 * 1/2**0.5 )
t.lt(45)
#t.lt(90)
#t.fd(l / 3) # turm dach flach (rechter Turm
#t.lt(90)
t.fd(l / 3)
t.rt(90)
t.fd(l / 3)
t.rt(90)
t.fd(l / 3) # rechte obere ecke vom linken turm
t.lt(45) # schräges dach rechte seite von rechtem turm
t.fd( (l /3) * 1/2**0.5 ) # länge vom schrägen dach
t.lt(90)
t.fd( l /3 * 1/2**0.5 )
t.lt(45)
#t.lt(90)
#t.fd(l / 3)
#t.lt(90)
t.fd(2 * l / 3)
t.lt(90)
t.end_fill()
def cannon(l=70):
t.begin_fill()
t.circle(25)
t.circle(25, 150)
t.fd(l)
t.lt(90)
t.fd(l / 7 * 2)
t.lt(90)
t.fd(l)
t.lt(180)
t.end_fill()
t.fd(l)
def paint(castlesize=100, ground=-200, leftpos=-500):
t.pensize(5)
t.pu()
t.goto(leftpos, ground)
t.pd
castle(castlesize)
t.fd(leftpos * -2)
t.color("blue", "green")
cannon()
t.setheading(45)
t.screensize(1600, 800)
castlesize = 200
ground = -200
leftpos = -500
speed = 10
play = True
heading = 45
wind = r.choice((-1, 1)) * round(r.random(), 4)
while play:
t.pu()
t.home()
t.clear()
t.speed(0)
t.pd()
paint(castlesize, ground, leftpos)
t.pd()
t.speed(10)
e.msgbox("Der wind hat die Geschwindigkeit : {}".format(wind))
heading = float(
e.enterbox(
"bitte geb den Winkel an! (z.B. 45.0)",
default="45.0"
)
)
speed = float(e.enterbox("bitte gebe die Geschwindigkeit an! (z.B. 10.0)", default="10.0"))
t.setheading(180 - heading)
dx = math.cos(t.heading() * math.pi / 180) * speed
dy = math.sin(t.heading() * math.pi / 180) * speed
y = ground
while y >= ground:
x = t.xcor()
y = t.ycor()
dy -= 0.1
x += dx
y += dy
t.goto(x, y)
play = e.boolbox("nochmal?")
t.exitonclick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment