I want to make a scenery with this code of fractals, and I need the fill color to change every second. I've tried a for-loop to redraw the whole thing, but that interferes with the other parts of my code that shouldn't be repeated
Is there a way turtle-graphics lets us change the fill color?
from turtle import *
from time import sleep, perf_counter
tracer(0)
def hilbert(size, level, parity):
if level == 0:
return
left(parity * 90)
hilbert(size, level - 1, -parity)
forward(size)
right(parity * 90)
hilbert(size, level - 1, parity)
forward(size)
hilbert(size, level - 1, parity)
right(parity * 90)
forward(size)
hilbert(size, level - 1, -parity)
left(parity * 90)
def fractal(dist, depth, dir):
if depth < 1:
fd(dist)
return
fractal(dist / 3, depth - 1, dir)
lt(60 * dir)
fractal(dist / 3, depth - 1, dir)
rt(120 * dir)
fractal(dist / 3, depth - 1, dir)
lt(60 * dir)
fractal(dist / 3, depth - 1, dir)
reset()
speed(0)
ht()
pu()
size = 6
setpos(-33*size, -32*size)
pd()
fillcolor("chocolate")
begin_fill()
fd(size)
hilbert(size, 6, 1)
fd(size)
for i in range(3):
lt(90)
fd(size*(64+i%2))
pu()
for i in range(2):
fd(size)
rt(90)
pd()
for i in range(4):
fd(size*(66+i%2))
rt(90)
end_fill()
update()
Output: