I'm putting together a program that reads information about angles and distances from a text file and draws it according to the information contained therein. The program should also calculate the azimuths, and that's what I did, these variables that start with azmt
represent the azimuth of each side of the polygon, but I did not do it the smarter way, because the code only runs to this specific file ("drawing.txt").
I would like the program to work for other ".txt" files as well (of course, as long as this file provides the necessary instructions). I've already been told that I could automate this part of the code using a for
loop, but it did not work out at all. Can someone give me a suggestion?
import turtle
f = open('desenho.txt')
turtle.speed(1)
turtle.mode("logo")
ang = []
dist = []
azmt = []
for line in f:
a = line.split(" ")
ang = ang + [float(a[0])]
dist = dist + [float(a[1])]
n = len(dist)
azmt0 = ang[0]
azmt1 = azmt0 + ang[1]
azmt2 = azmt1 + ang[2]
azmt3 = azmt2 + ang[3]
azmt4 = azmt3 + ang[4]
azmt5 = azmt4 + ang[5]
azmt6 = azmt5 + ang[6]
azmt7 = azmt6 + ang[7]
azmt8 = azmt7 + ang[8]
azmt9 = azmt8 + ang[9]
azmt10 = azmt9 + ang[10]
azmt11 = azmt10 + ang[11]
azmt = [float(azmt0)]+[float(azmt1)]+[float(azmt2)]+[float(azmt3)]+[float(azmt4)]+[float(azmt5)]+[float(azmt6)]+[float(azmt7)]+[float(azmt8)]+[float(azmt9)]+[float(azmt10)]+[float(azmt11)]
print(azmt)
for i in range(n):
turtle.rt(ang[i])
turtle.fd(dist[i])
turtle.done()