-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbezier.py
More file actions
78 lines (78 loc) · 2.22 KB
/
bezier.py
File metadata and controls
78 lines (78 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import turtle
from tkinter import *
def run():
turtle.screensize(1920,1080)
point=[]
temp = [float(x1.get()), float(y1.get())]
point.append(temp)
temp = [float(x2.get()), float(y2.get())]
point.append(temp)
temp = [float(x3.get()), float(y3.get())]
point.append(temp)
temp = [float(x4.get()), float(y4.get())]
point.append(temp)
temp = [float(x5.get()), float(y5.get())]
point.append(temp)
temp = [float(x6.get()), float(y6.get())]
point.append(temp)
turtle.penup()
turtle.pensize(2)
for i in point:
turtle.goto(i[0],i[1])
turtle.pendown()
turtle.goto(point[0][0],point[0][1])
turtle.penup()
turtle.goto(point[0][0],point[0][1])
turtle.pendown()
turtle.pensize(1)
turtle.pencolor('red')
T=0.001
while T<1:
B0=(1-T)**6
B1=6*T*(1-T)**5
B2=15*T**2*(1-T)**4
B3=20*T**3*(1-T)**3
B4=15*T**4*(1-T)**2
B5=6*T**5*(1-T)**1
B6=T**6
x=B0*point[0][0]+B1*point[1][0]+B2*point[2][0]+B3*point[3][0]+B4*point[4][0]+B5*point[5][0]+B6*point[0][0]
y=B0*point[0][1]+B1*point[1][1]+B2*point[2][1]+B3*point[3][1]+B4*point[4][1]+B5*point[5][1]+B6*point[0][1]
turtle.goto(x,y)
T+=0.001
turtle.mainloop()
tk=Tk()
tk.title("输出贝塞尔曲线: ")
Label(tk,text="输入顶点:").grid(row=0)
Label(tk,text="1:").grid(row=1)
Label(tk,text="2:").grid(row=2)
Label(tk,text="3:").grid(row=3)
Label(tk,text="4:").grid(row=4)
Label(tk,text="5:").grid(row=5)
Label(tk,text="6:").grid(row=6)
x1=Entry(tk)
x2=Entry(tk)
x3=Entry(tk)
x4=Entry(tk)
x5=Entry(tk)
x6=Entry(tk)
x1.grid(row=1,column=1)
x2.grid(row=2,column=1)
x3.grid(row=3,column=1)
x4.grid(row=4,column=1)
x5.grid(row=5,column=1)
x6.grid(row=6,column=1)
y1=Entry(tk)
y2=Entry(tk)
y3=Entry(tk)
y4=Entry(tk)
y5=Entry(tk)
y6=Entry(tk)
y1.grid(row=1,column=2,padx=5,pady=5)
y2.grid(row=2,column=2,padx=5,pady=5)
y3.grid(row=3,column=2,padx=5,pady=5)
y4.grid(row=4,column=2,padx=5,pady=5)
y5.grid(row=5,column=2,padx=5,pady=5)
y6.grid(row=6,column=2,padx=5,pady=5)
Button(tk,text="开始绘制",width=10,command=run).grid(row=7,column=1,pady=5)
Button(tk,text="退出程序",width=10,command=tk.quit).grid(row=7,column=2,pady=5)
tk.mainloop()