When I use turtle no matter what I get this error message:
File "[REDACTED FOR SECURITY]", line 1, in <module>
from turtle import *
File "[REDACTED FOR SECURITY]", line 5, in <module>
turtle.bgcolor('black')
AttributeError: partially initialized module 'turtle' has no attribute 'bgcolor' (most likely due to a circular import)
I wasn't even using turtle.bgcolor()
.
Here is my code, to draw a fern:
from turtle import *
import random
pen = turtle.Turtle()
pen.speed(15)
pen.color("blue")
pen.penup()
x = 0
y = 0
for n in range(110000):
pen.goto(65 * x, 37 * y - 252) # 57 is to scale the fern and -275 is to start the drawing from the bottom.
pen.pendown()
pen.dot()
pen.penup()
r = random.random() # to get probability
r = r * 100
xn = x
yn = y
if r < 1: # elif ladder based on the probability
x = 0
y = 0.16 * yn
elif r < 86:
x = 0.85 * xn + 0.04 * yn
y = -0.04 * xn + 0.85 * yn + 1.6
elif r < 93:
x = 0.20 * xn - 0.26 * yn
y = 0.23 * xn + 0.22 * yn + 1.6
else:
x = -0.15 * xn + 0.28 * yn
y = 0.26 * xn + 0.24 * yn + 0.44