Upload code

This commit is contained in:
2025-01-20 19:40:14 +01:00
parent 71625e3e41
commit 07809d7d77
66 changed files with 8917 additions and 0 deletions

72
RandomTurtle/Binäruhr.py Executable file
View File

@@ -0,0 +1,72 @@
import turtle
import datetime
import time
#Setup
turtle.ht()
turtle.tracer(0)
turtle.speed(0)
#Definition der Kreise
def circles(fill):
turtle.pu()
turtle.bk(20)
turtle.pd()
if fill == 0:
turtle.circle(10)
else:
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.pu()
turtle.home()
turtle.pu()
turtle.bk(25)
#Postitionieren der Turtle
def distance(pixels):
turtle.home()
turtle.pu()
turtle.lt(90)
turtle.bk(pixels)
turtle.rt(90)
#Berechnen der einzelnen Stellen
def main():
turtle.clear()
turtle.home()
h = datetime.datetime.now().hour
min = datetime.datetime.now().minute
sec = datetime.datetime.now().second
hr_pos2 = h//2
mn_pos2 = min//2
sk_pos2 = sec//2
for i in range(6):
hr_pos2 = hr_pos2 // 2
hr_pos = hr_pos2 % 2
circles(hr_pos)
distance(50)
for i in range(7):
mn_pos2 = mn_pos2 // 2
mn_pos = mn_pos2 % 2
circles(mn_pos)
distance(100)
for i in range(7):
sk_pos2 = sk_pos2 // 2
sk_pos = sk_pos2 % 2
circles(sk_pos)
turtle.update()
#Ausführen
while True:
main()
time.sleep(0.1)

48
RandomTurtle/Digitale Uhr.py Executable file
View File

@@ -0,0 +1,48 @@
from turtle import*
import datetime
import time
style = ("Minecraftia", 75, "normal")
tracer(0)
#Ausführen der Uhr.
while True:
time.sleep(1)
clear()
ht()
pu()
sec = datetime.datetime.now().second
min = datetime.datetime.now().minute
h = datetime.datetime.now().hour
bk(350)
#Abstände definieren
if h >= 10:
write(h, font=style)
fd(200)
else:
write("0", font=style)
fd(100)
write(h, font=style)
fd(100)
write(":", font=style, align = "left")
fd(50)
if min >= 10:
write(min, font=style)
fd(200)
else:
write("0", font=style)
fd(100)
write(min, font=style)
fd(100)
write(":", font=style, align = "left")
fd(50)
if sec >= 10:
write(sec, font=style)
fd(200)
else:
write("0", font=style)
fd(100)
write(sec, font=style)
fd(100)
home()
update()

25
RandomTurtle/Dots.py Executable file
View File

@@ -0,0 +1,25 @@
from turtle import*
import time
def scene(d):
dot(500/d)
ht()
color("red")
bgcolor("black")
pu()
tracer(0)
lt(90)
bk(120)
a = 200
for i in range(200):
clear()
scene(a)
update()
a -= 1
time.sleep(0.025)
fd(1)

View File

@@ -0,0 +1,36 @@
from turtle import *
import time
r = numinput("PENTAGON","Wie gross soll die Seitenlänge des Pentagons sein?",200)
rl = numinput("PENTAGON","Wie viele Ebenen sollen benuzt werden?",3)
tracer(0)
def pentagon(n, radius):
if n == 0:
#ausgefülltes Pentagon zeichnen
color("Red")
begin_fill()
for i in range(5):
fd(radius)
rt(360/5)
end_fill()
else:
for i in range(5):
#Positionierung der Turtle
pu()
fd(radius * 2.62 * 0.381966)
rt(360/5)
pd()
#Rekursion
pentagon(n - 1,radius * 0.381966)
update()
starttime = time.time()
pu()
lt(90)
fd(r)
rt(90)
bk(r*0.6)
pd()
pentagon(rl, r)
exitonclick();

14
RandomTurtle/Halbkreis.py Executable file
View File

@@ -0,0 +1,14 @@
from turtle import*
speed(10000)
ht()
def kreis_halb(anzahl_seiten,radius):
for i in range(anzahl_seiten):
fd(radius / anzahl_seiten)
rt(360 / anzahl_seiten)
kreis_halb(500,800)
exitonclick()

87
RandomTurtle/Huhn.py Executable file
View 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()

17
RandomTurtle/Kleeblatt.py Executable file
View File

@@ -0,0 +1,17 @@
from turtle import*
speed(1000)
def blatt(seite,winkel,anzahl):
for i in range(anzahl):
begin_fill()
for i in range(3):
fd(seite)
lt(winkel)
end_fill()
rt(360/anzahl)
ht()
color("green")
blatt(100,120,4)
exitonclick()

View File

@@ -0,0 +1,35 @@
import random
import turtle
import time
turtle.pu()
def vieleck_random_randomize():
for i in range(random.randint(25, 100)):
turtle.color(random.random(),random.random(),random.random())
size = random.randint(50, 200)
turtle.width(random.randint(2, 10))
ecken = random.randint(3, 20)
turtle.setpos(random.randint(-300,300), random.randint(-300,300))
fuellen = random.randint(0,1)
turtle.pd()
if fuellen >= 1:
turtle.begin_fill()
for i in range(ecken):
turtle.fd(size / ecken)
turtle.rt(360 / ecken)
turtle.end_fill()
else:
for i in range(ecken):
turtle.fd(size / ecken)
turtle.rt(360 / ecken)
turtle.pu()
print("Random Design")
draw_time_start = time.time()
vieleck_random_randomize()
draw_time_end = time.time()
print("Drawing has taken", draw_time_end - draw_time_start , "seconds")
print("Click to exit")
turtle.exitonclick();

11
RandomTurtle/Progressbar.py Executable file
View File

@@ -0,0 +1,11 @@
import time
import os
while True:
for i in range(4):
print("=", end=" ",flush=True)
time.sleep(0.5)
print("=", end="\r",flush=True)
time.sleep(0.5)
os.system( 'cls' )
time.sleep(0.5)

16
RandomTurtle/Striche.py Executable file
View File

@@ -0,0 +1,16 @@
from turtle import*
dicke = 3
lt(90)
for i in range(10):
fd(100)
bk(100)
rt(90)
pu()
fd(20)
pd()
lt(90)
width(dicke)
dicke += 2

View File

@@ -0,0 +1,7 @@
from turtle import*
a = int(numinput("Wie alt bist du?", "Bitte als Zahl eingeben",16,minval=1,maxval=100))
while (a>=16) and (a<=20):
fd(100)
a = 1

187
RandomTurtle/TicTacToe.py Executable file
View File

@@ -0,0 +1,187 @@
#TICTACTOE V 1.0
import time
#Variables5
global bd
bd = [[0,0,0],[0,0,0],[0,0,0]]
global filled_fields
filled_fields = 0
global player
global playershow
playershow = 1
player = 1
global play
play = 1
#FUNCTIONS
#--------------------
def inputs():
global playershow
global bd
print("It's the turn of player", playershow)
m = input("Where do you want to put your mark? ")
if len(m) > 1:
sp = m[0]
zl = m[1]
z = int(zl) - 1
s = ord(sp) - 65
if bd[z][s] > 0:
print("""
THAT FIELD IS ALREADY TAKEN, CHOOSE DIFFERENT ONE!
""")
else:
inputremap(z,s)
else:
print("""
PLEASE TYPE IN A LEGIT COORDINATE:
FORM: Coordinate Y Coordinate X --> Ex. A1/A2
""")
def inputremap(z, s):
global player
global playershow
global bd
bd[z][s] = player
if playershow == 1:
playershow = 2
player = 7
else:
playershow = 1
player = 1
global filled_fields
filled_fields += 1
full(filled_fields)
def winning():
global play
global bd
x = 0
y = 0
global go
go = 1
count = 0
print("""
checking for winner
""")
while go == 1:
if sum(bd[x]) == 3:
go = 0
play = 0
print("The Winner is player 1")
elif sum(bd[x]) == 21:
go = 0
play = 0
print("The Winner is player 2")
elif bd[0][y] + bd[1][y] + bd[2][y] == 3:
go = 0
play = 0
print("The Winner is player 1")
elif bd[0][y] + bd[1][y] + bd[2][y] == 21:
go = 0
play = 0
print("The Winner is player 2")
else:
x += 1
y += 1
if count >= 2:
go = 0
print("""no winner yet
""")
else:
count += 1
def full(filled_field):
global bd
if filled_field == 9:
print("draw")
global play
play = 0
else:
winning()
#BOARD DRAWING
def board_draw():
print("\n")
xx = 0
yy = 0
global bd
while yy < 3:
while xx < 3:
if bd[xx][yy] == 0:
print(" ", end = " ")
elif bd[xx][yy] == 1:
print(" X ", end = " ")
elif bd[xx][yy] == 7:
print(" O ", end = " ")
else:
print(""" CRITICAL ERROR""")
if xx < 2:
print("|", end = " ")
else:
print(" ", end = " ")
xx += 1
print(" ")
xx = 0
if yy < 2:
print("----------------------")
else:
print(" ")
yy += 1
#MAIN CYCLE
print(50*("\n"))
print("""
------------------------------------------------------
TIC TAC TOE
===========
V 1.0
V 2021.06.18
by Janis Hutz
""")
time.sleep(2)
print("starting...")
time.sleep(3)
print("\n\n\n")
goahead = 1
print("""
| |
----------------
| |
----------------
| |
""")
while goahead == 1:
while play == 1:
inputs()
board_draw()
time.sleep(2)
print("""
REPLAY?
""")
i = input("""Choose: (y/n)""")
if i == "y":
goahead = 1
play = 1
else:
goahead = 0
print("""
GOOD BYE!
""")

43
RandomTurtle/blume.py Executable file
View File

@@ -0,0 +1,43 @@
from turtle import*
lt(90)
width(3)
speed(1000)
def stiel(orientation):
color("green")
for i in range(50):
if orientation > 1 and orientation < 3:
fd(7)
lt(1)
else:
fd(7)
rt(1)
def leaves():
color("red")
for i in range(100):
fd(3)
rt(360/100)
def blume(orientation_in,blaetter):
stiel(orientation_in)
for i in range(blaetter):
leaves()
rt(360/blaetter)
ht()
blume(2,5)
pu()
home()
fd(50)
lt(90)
pd()
blume(1,10)
exitonclick()