from turtle import*
def pract(a,d):
if d<=20: return
for i in range(4):
fd(d)
lt(a)
lt(a)
fd(d)
rt(a/2)
pract(a,d*(2**(1/2)/2))
setup(800, 800)
up(); goto(0, -300); down()
speed(5)
pract(90,100)
done()
It's a Python Fractal problem. I made it on one side I'm asking you a question because I couldn't add it.
python3 turtle
from turtle import *
def pract(d):
"""
x
x_________
| |
| |
| |
._________|
. Start at a point and draw a square
Draw a small square at point x.
Finish the work and return to the initial starting point
The direction is also returned to the original direction.
"""
if d <= 20:
return
dd = d * (2 ** (1 / 2) / 2)
for _ in range(4):
fd(d)
lt(90)
lt(90)
fd(d)
rt(45)
# Draw a small rectangle from the initial direction to lt 45 degrees at the first x point
pract(dd)
up()
fd(dd)
rt(90)
down()
# Draw a small rectangle from the initial direction to rt 45 degrees at the second x-point
pract(dd)
up()
rt(90)
fd(dd)
lt(45)
fd(d)
lt(90)
down()
# The position and orientation at the end shall be the position and orientation at the start.
setup(800, 800)
up()
goto(0, -300)
down()
speed(5)
pract(100)
done()
© 2024 OneMinuteCode. All rights reserved.