使用海龟绘图。输入多个点,将这些点都两两相连。
作者:互联网
使用海龟绘图。输入多个点,将这些点都两两相连。
import turtle
def con_line(xpoint_set,ypoint_set):
"""将输入点两两相连"""
turtle.pensize(2)#调整画笔粗细
turtle.speed(1)#设置画笔速度
n=0
for i,j in zip(xpoint_set,ypoint_set):#外循环遍历所有点
turtle.penup() #提笔
turtle.goto(i,j)
turtle.pendown() #落笔
n += 1
m = 0
for x, y in zip(xpoint_set, ypoint_set):#内循环连接所有点一次
m += 1
if m >= n:
turtle.goto(x,y)
turtle.penup() # 提笔
turtle.goto(i,j)
turtle.pendown() # 落笔
turtle.hideturtle()#隐藏海归
turtle.done()#保留窗口不被销毁
if __name__ == '__main__':
xpoint_set = list(map(int,input("x点集:").split(" ")))#x点集
ypoint_set = list(map(int,input("y点集:").split(" ")))#y点集
con_line(xpoint_set,ypoint_set)
标签:turtle,__,set,点集,绘图,ypoint,海龟,xpoint,输入 来源: https://blog.csdn.net/qq_51912956/article/details/121297364