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.

69 lines
2.1 KiB

import math
# print(math.cos(math.radians(90)))
#
# start=(440,670)
# print(start[0]+200*math.cos(math.radians(90)))
# print(start[1] - 200 * math.sin(math.radians(90)))
import tkinter as tk
# 创建主窗口
root = tk.Tk()
root.title("绘制Y形")
# 设置画布
canvas = tk.Canvas(root, bg="white", width=1000, height=700)
canvas.pack()
def draw_shape():
# 绘制三角形
point1 = [(150, 20), (50, 200), (250, 200)]
canvas.create_polygon(point1, outline='black', fill='white', width=2)
# 绘制菱形
point2 = [(150, 240), (50, 360), (150, 480), (250, 360)]
canvas.create_polygon(point2, outline='black', fill='white', width=2)
# 绘制 Y形
canvas.create_line(340, 20, 420, 80, fill='blue3', width=2) # 画左臂
canvas.create_line(510, 20, 420, 80, fill='blue3', width=2) # 画右臂
canvas.create_line(420, 180, 420, 80, fill='blue3', width=2) # 画中心线
# 绘制圆形
canvas.create_oval(340, 240, 540, 440, width=2)
# 绘制直线
canvas.create_line(330, 470, 550, 470, fill='blue3', width=2)
# 绘制正方形
canvas.create_rectangle(650, 420, 800, 270, width=2)
# root=tk.Tk()
# canvas = tk.Canvas(root, bg="white", highlightthickness=1, highlightbackground="tomato")
# canvas.config(width=1000, height=700)
# canvas.place(x=50, y=50)
#
# canvas.pack()
draw_shape()
root.mainloop()
def draw_rect(x, y, w, a):
coord = (x, y, x - w * math.cos(math.radians(a)), y + w * math.sin(math.radians(a)), \
x - math.sqrt(2) * w * math.sin(math.radians(a + 45)),
y - math.sqrt(2) * w * math.cos(math.radians(a + 45)), \
x - w * math.sin(math.radians(a)), y - w * math.cos(math.radians(a)))
canvas.create_polygon(coord, fill='', outline='black')
root = tk.Tk()
root.geometry('1000x800')
canvas = tk.Canvas(root, bg="white", highlightthickness=1, highlightbackground="tomato")
canvas.config(width=1000, height=700)
canvas.pack()
a = 0
# 实现边长增加5旋转度数增加5
for i in range(5, 301, 5):
draw_rect(400, 400, i, a)
canvas.update()
a += 5
root.mainloop()