Upload code
This commit is contained in:
87
RandomTurtle/Huhn.py
Executable file
87
RandomTurtle/Huhn.py
Executable file
@@ -0,0 +1,87 @@
|
||||
import turtle
|
||||
import math
|
||||
import random
|
||||
|
||||
turtle.title("Huhn")
|
||||
sideay = int(turtle.numinput("Huhn", "Punkt A, cord y", -100))
|
||||
sideax = int(turtle.numinput("Huhn", "Punkt A, cord x", 200))
|
||||
sideby = int(turtle.numinput("Huhn", "Punkt B, cord y", -100))
|
||||
sidebx = int(turtle.numinput("Huhn", "Punkt B, cord x", -200))
|
||||
sidecy = int(turtle.numinput("Huhn", "Punkt C, cord y", 200))
|
||||
sidecx = int(turtle.numinput("Huhn", "Punkt C, cord x", 0))
|
||||
anzahl_durchgaenge = int(turtle.numinput("Huhn", "Anzahl Durchgänge", 10, minval=1, maxval=100))
|
||||
stiftdicke = int(turtle.numinput("Huhn", "Stiftdicke", 2, minval=1, maxval=50))
|
||||
durchgang = 0
|
||||
|
||||
|
||||
turtle.speed(0)
|
||||
cage = turtle.Turtle()
|
||||
huhn = turtle.Turtle()
|
||||
|
||||
cage.ht()
|
||||
huhn.pu()
|
||||
huhn.ht()
|
||||
|
||||
|
||||
def motion(sideay,sideax,sideby,sidebx,sidecy,sidecx,stiftdicke):
|
||||
edge = random.randint(1,3)
|
||||
if edge == 1:
|
||||
x = sideax
|
||||
y = sideay
|
||||
else:
|
||||
if edge == 2:
|
||||
x = sidebx
|
||||
y = sideby
|
||||
else:
|
||||
x = sidecx
|
||||
y = sidecy
|
||||
|
||||
huhn.setheading(huhn.towards(x, y))
|
||||
nextpos = (math.sqrt((x - huhn.xcor())**2 + (y - huhn.ycor()) **2)) / 2
|
||||
huhn.fd(nextpos)
|
||||
huhn.pd()
|
||||
huhn.dot(stiftdicke)
|
||||
huhn.pu()
|
||||
|
||||
def motion_pre(sideay,sideax,sideby,sidebx,sidecy,sidecx,stiftdicke):
|
||||
edge = random.randint(1,3)
|
||||
if edge == 1:
|
||||
x = sideax
|
||||
y = sideay
|
||||
else:
|
||||
if edge == 2:
|
||||
x = sidebx
|
||||
y = sideby
|
||||
else:
|
||||
x = sidecx
|
||||
y = sidecy
|
||||
|
||||
huhn.setheading(huhn.towards(x, y))
|
||||
nextpos = (math.sqrt((x - huhn.xcor())**2 + (y - huhn.ycor()) **2)) / 2
|
||||
huhn.fd(nextpos)
|
||||
|
||||
def cagedraw(sideax,sideay,sidebx,sideby,sidecx,sidecy):
|
||||
cage.pu()
|
||||
cage.setpos(sideax,sideay)
|
||||
cage.pd()
|
||||
cage.setpos(sidebx,sideby)
|
||||
cage.setpos(sidecx,sidecy)
|
||||
cage.setpos(sideax,sideay)
|
||||
|
||||
|
||||
print("Started drawing Triangle")
|
||||
cagedraw(sideax,sideay,sidebx,sideby,sidecx,sidecy)
|
||||
|
||||
print("Started mapping... Printing Points of Tranche:")
|
||||
turtle.tracer(1000)
|
||||
print("initialisation")
|
||||
for i in range(50):
|
||||
motion_pre(sideay,sideax,sideby,sidebx,sidecy,sidecx,stiftdicke)
|
||||
|
||||
for i in range(anzahl_durchgaenge):
|
||||
for i in range(1000):
|
||||
motion(sideay,sideax,sideby,sidebx,sidecy,sidecx,stiftdicke)
|
||||
durchgang += 1
|
||||
print(durchgang,"/", anzahl_durchgaenge)
|
||||
print("done, click to exit")
|
||||
turtle.exitonclick()
|
||||
Reference in New Issue
Block a user