actually added the content 🤦

This commit is contained in:
Surferlul 2021-11-05 14:54:28 +01:00
parent 41ee9f8558
commit b7de24ee5d
4 changed files with 160 additions and 1 deletions

BIN
Levy_C.ctb Normal file

Binary file not shown.

View File

@ -1,2 +1,2 @@
# Levy_C
A turtle (python) implementation of the Lévy C curve (that i seem to have forgotten to upload)
A turtle (python) implementation of the Lévy C curve

131
levy_c_full.py Normal file
View File

@ -0,0 +1,131 @@
import turtle
t=turtle.Turtle()
n = int(input("Recursion Depth [-1 for inf]:"))
if n<0:
color_diff = 1
else:
color_diff = 1/(n+1)
color = [0,0,1]
while True:
a = input("Starting Structure [I for one line, L for l-shape, C for custom]:")
if a.upper() == "I":
s=[(0, True)]
elif a.upper() == "L":
s = [(-90, True), (90, True)]
elif a.upper() == "C":
s = eval(input("Input custom starting structure [Format: [(int Rotation, bool Walk first), (int Rotation, bool Walk first)]]:\n"))
else:
print("Invalid input!")
continue
break
m = input("Size Multiplier [default 50]:")
if m:
m=int(m)
else:
m=50
speed = input("speed [default 0]:")
if speed:
speed=int(speed)
else:
speed=0
clr = input("Color (many times slower) [default 0]")
if clr:
clr = int(clr)
else:
clr = 0
r = input("Start Rotation [default 0]:")
if r:
r=int(r)
else:
r=0
frm = input("Display from [default 0]:")
if frm:
frm=int(frm)
else:
frm=0
to = input("Display to [default inf]:")
if to:
to=int(to)
else:
to=9e999
if -1>speed>10:
t.speed(10-speed)
else:
turtle.tracer(0, 0)
def draw_arr(arr, multiplier=50, step=1, frm=0, to=9e999):
x=0
rot=0
for i,j in arr:
if x >= frm and x <= to:
if j:
if rot:
t.right(rot)
t.forward(multiplier)
t.right(i)
rot=0
else:
rot += i
if step>1:
if not x % step:
turtle.update()
x+=1
t.right(rot)
def levy_c(n, rotations, start_rotation=0):
def gen(n):
yield start_rotation, False
if n == 0:
yield from next(rotations)
else:
yield 45, False
if clr:
color[0] += color_diff
color[2] -= color_diff
t.color(tuple(color))
yield from gen(n-1)
if clr:
color[0] -= color_diff
color[2] += color_diff
t.color(tuple(color))
yield -90, False
yield from gen(n-1)
yield 45, False
while True:
yield gen(n)
def arr_generator(arr):
def gen():
for i in arr:
yield i
while True:
yield gen()
def optimize_arr(arr):
for i in range(len(arr)):
while len(arr) > i+1 and not arr[i+1][1]:
arr[i] = ((arr[i][0] + arr.pop(i+1)[0])%360, arr[i][1])
return arr
s = arr_generator(s)
if n < 0:
while True:
turtle.update()
if not clr:
s = arr_generator(optimize_arr([i for i in next(s)]))
s = levy_c(1, s)
t.right(-45)
draw_arr(next(s), multiplier=m, step=speed, frm=frm, to=to)
color_diff=1/(1/color_diff+1)
else:
draw_arr(next(levy_c(n, s, r)), multiplier=m, step=speed, frm=frm, to=to)
turtle.update()
input("Done!")

28
levy_c_minimal.py Normal file
View File

@ -0,0 +1,28 @@
#!/bin/python3
import turtle
turtle.speed(int(input("Speed[ 0 - fastest, 10 - slowest ]:"))) # geschwindigkeit einlesen und festlegen
def levy_c(n:int, tp:str="I", size:int=50):
"""
n:int = rekursionstiefe
tp:str = typ des anfangspunktes (I oder L)
size:int = größe der gezeichneten linien
"""
if n == 0: # abbruchsbedingung
if tp=="I": # je nach typ grundstruktur zeichnen
turtle.forward(size) # einen einzelnen Strich für I
else:
turtle.forward(size) # eine L-förmige Struktur für L
turtle.right(-90)
turtle.forward(size)
turtle.right(90)
else:
turtle.right(45) # der rekursive aufruf von Levy C
levy_c(n-1, tp, size) # die nächst kleinere rekursion wird aufgerufen
turtle.right(-90)
levy_c(n-1, tp, size) # ^
turtle.right(45)
levy_c(int(input("Recursion Depth:")), tp=input("Type [I or L]"), size=int(input("Size Multiplier:")))
# rekursionstiefe, typ des anfangspunktes und größe der gezeichneten linien werden eingelesen
input("Done!")