Created
March 3, 2015 17:35
-
-
Save horstjens/905b6ea46a63ee2ed81e to your computer and use it in GitHub Desktop.
turtle_example_leon.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python3 example to play with turtle graphic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import easygui as e | |
import random as r | |
import turtle as t | |
import sys | |
def k1(): | |
leobold.fd(30) | |
def k2(): | |
leobold.left(15) | |
def k3(): | |
leobold.right(15) | |
def k4(): | |
leobold.back(30) | |
def k5(): | |
leobold.pencolor(r.randint(0,255), | |
r.randint(0,255), | |
r.randint(0,255)) | |
leobold.circle(50) | |
def groesserrandom(): | |
leobold.pensize(r.randint(0,30)) | |
def crazy(): | |
for x in range(5): | |
# leobold.fd(r.randint(-100,100)) | |
leobold.lt(r.randint(0,360)) | |
farbwechsel() | |
haus(r.randint(50,250)) | |
def zufallsfarbe(): | |
leobold.pencolor(r.randint(0,255), | |
r.randint(0,255), | |
r.randint(0,255)) | |
def gruen(): | |
leobold.pencolor(r.randint(0,255), | |
r.randint(0), | |
r.randint(0)) | |
def brav(): | |
leobold.up() | |
leobold.home() | |
leobold.down() | |
def check(): | |
print("Deine Größe:",+leobold.pensize()) | |
print("Deine Farbe: {}".format(leobold.pencolor())) | |
print("Dein Name: {}".format(lo)) | |
def kleini(): | |
leobold.pensize(leobold.pensize()-1) | |
def grosi(): | |
leobold.pensize(leobold.pensize()+1) | |
def skip(): | |
lokolo = e.buttonbox("Hast du genug?","Hmm...",["Weiterspielen","Beenden"]) | |
if lokolo =="Weiterspielen": | |
e.msgbox("Danke! Jetzt kann ich weiter spielen {}".format(lo),"Turtle") | |
else: | |
sys.exit() | |
def haus(hoehe=50): | |
leobold.left(90) | |
leobold.fd(hoehe) | |
leobold.right(45) | |
leobold.fd(hoehe/2) | |
leobold.right(90) | |
leobold.fd(hoehe/2) | |
leobold.right(45) | |
leobold.fd(hoehe) | |
leobold.right(90) | |
leobold.fd(hoehe/5*3) | |
def move_second(): | |
auto.back(100) | |
auto.forward(200) | |
auto.back(100) | |
screen.ontimer(move_second) | |
def main(): | |
taste = e.enterbox("Wähle Knopf willst du für das Beenden definieren:")[0] | |
e.msgbox("Pfeil Oben = Turtle geht 1 Schritt geradeaus \nPfeil Links = Turtle dreht sich um 15° nach links \nPfeil Rechts = Turtle dreht sich um 15° nach rechts \nPfeil Unten = Turtle fährt 1 Schritt rückwärts \no = Turtle malt ein Kreis \nc = Das Terminal zeigt dir deine Werte der Turtle an \n1 = Größere Schrift \n0 = Kleinere Schrift \n2 = Zufällige Farbe wählen \np = zDie Dicke von der Turtle wird zufällig bestimmt") | |
t.setup(640,400) | |
t.title("Name: {}".format(lo)) | |
hol = e.buttonbox("Möchtest du Fortfahren?","HierSchauBox",["Fortfahren","Abbrechen"]) | |
if hol =="Fortfahren": | |
e.msgbox("Viel Spaß!") | |
else: | |
sys.exit() | |
leobold.pensize(7) | |
t.onkey(k1, "Up") | |
t.onkey(k2, "Left") | |
t.onkey(k3, "Right") | |
t.onkey(k4, "Down") | |
t.onkey(k5, "o") | |
t.onkey(crazy, "r") | |
t.onkey(brav, "s") | |
t.onkey(kleini, "0") | |
t.onkey(grosi, "1") | |
t.onkey(haus, "h") | |
t.onkey(check, "c") | |
t.onkey(zufallsfarbe, "2") | |
t.onkey(skip, taste) | |
t.onkey(groesserrandom, "p") | |
screen.ontimer(move_second) | |
screen.onscreenclick(auto.goto) | |
t.listen() | |
t.mainloop() | |
return 0 | |
if __name__ == '__main__': | |
leobold = t.Turtle() | |
auto = t.Turtle() | |
screen= t.Screen() | |
screen.colormode(255) | |
lo = e.enterbox("Gib deinen Namen ein:","Hallobox") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment