生成螺旋路线图

# -*- coding: utf-8 -*-
"""
Created on Tue Jul 24 14:53:27 2018

@author: syn.van
"""
import numpy as np
import time

a1 = np.zeros((100,2)) #建立一个100*2的数组,储存100个转弯点
n=100

a1[0]=(0,0)#首先给起点赋值  

print(a1[0][1])
#首先对横坐标进行处理
a=-3
c=[]
for num in range(1,100):
    b=num
    
    #print(num)
        
    if(b%4==0):
        a=a+4
        c.append(a)
        
        print(a)

d=1
for i in c:
    
    a1[i][0]=10*d
    a1[i+1][0]=10*d
    a1[i+2][0]=-10*d

    a1[i+3][0]=-10*d
    d=d+1
print (a1)   
'''
上面对横坐标进行修改
下面对纵坐标进行修改

'''    
e=1
for i in c:
    
    a1[i+1][1]=10*e
    a1[i+2][1]=10*e
    a1[i+3][1]=-10*e
    a1[i+4][1]=-10*e
   
    e=e+1
  
print (a1.shape)
a1=np.delete(a1,[98,99],axis=0)
  
print (a1)

ff=np.mat(a1)
print (ff)

filename=("1.txt")
with open(filename,'w') as file_object:
    for i in range(1,97):
        
        file_object.write(str(a1[i])+"\n")
        
        
import turtle 

import numpy as np 

turtle.screensize( bg='yellow')   
turtle.title('路径模拟')
turtle.setup(600, 600, 500,500 )
  
pen = turtle.Turtle()
pen.color("black")
pen.width(3)
pen.shape("turtle")
pen.speed(2)


'''a=np.array([
        [50,50],
        [0,35]]
        
        )
print (a)'''

for n in range(0,98):
    pen.down()
    pen.goto(a1[n])
  
    #time.sleep(1)
   








       
    
        

猜你喜欢

转载自blog.csdn.net/qq_33169543/article/details/81189112