You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.2 KiB

11 months ago
def Y_pattern():
canvas.delete("all") # 清除画布
canvas.create_line(20, 30, 110, 90, fill='red', width=2) # 左臂
canvas.create_line(170, 30, 110, 90, fill='red', width=2) # 右臂
canvas.create_line(80, 160, 80, 90, fill='red', width=2) # 中心线
def Y_tree(depth, percent, left_angle, right_angle, start_point, angle, length, canvas):
if depth == 0:
return
end_point = (start_point[0] + length * math.cos(math.radians(angle)),
start_point[1] - length * math.sin(math.radians(angle)))
canvas.create_line(start_point, end_point, fill=color, width=2)
Y_tree(depth - 1, percent, left_angle, right_angle, end_point, angle + right_angle, length * percent,
canvas) # 画右枝
Y_tree(depth - 1, percent, left_angle, right_angle, end_point, angle - left_angle, length * percent,
canvas) # 画左枝
canvas.update()
sleep(0.001)
Y_tree(finishLevel, treePercent, leftAngle, rightAngle, initPoint, initAngle, initLong, canvas)
Y_pattern()
分形层数:finishLevel=10
缩放比例:treePercent=0.7
左枝倾角:leftAngle=90
右枝倾角:rightAngle=180
初始点:initPoint=(520, 600)
初始角:initAngle=90
初始长度:initLong=150
颜色:color="#85bbd1"