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.
50 lines
1.5 KiB
50 lines
1.5 KiB
5 months ago
|
# FH的python代码
|
||
|
# 文本分析和图像识别
|
||
|
# 开发时间 2023/7/17 17:07
|
||
|
import tkinter as tk
|
||
|
import math
|
||
|
|
||
|
root = tk.Tk()
|
||
|
cv_small = tk.Canvas(root, width=220, height=180)
|
||
|
cv_small.pack()
|
||
|
|
||
|
cv_small.delete("all") # 清除画布
|
||
|
cv_small.create_line(50, 30, 110, 90, fill='red', width=2) # 左臂
|
||
|
cv_small.create_line(170, 30, 110, 90, fill='red', width=2) # 右臂
|
||
|
cv_small.create_line(110, 160, 110, 90, fill='red', width=2) # 中心线
|
||
|
|
||
|
root.mainloop()
|
||
|
|
||
|
|
||
|
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='LightBlue4', width=2)
|
||
|
# canvas.update()
|
||
|
# canvas.after(1)
|
||
|
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) # 画左枝
|
||
|
# print(start_point,end_point)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
root = tk.Tk()
|
||
|
canvas = tk.Canvas(root, width=1200, height=1000)
|
||
|
canvas.pack()
|
||
|
|
||
|
start_point = (300, 600)
|
||
|
angle = 45
|
||
|
length = 200
|
||
|
depth = 12
|
||
|
percent = 0.7
|
||
|
left_angle = 30
|
||
|
right_angle = 30
|
||
|
|
||
|
Y_tree(depth, percent, left_angle, right_angle, start_point, angle, length, canvas)
|
||
|
|
||
|
root.mainloop()
|