0
I’m putting together a program that reads information about angles and distances from a text file and draws according to the information contained there. The program should also calculate azimuths, and that’s what I did, those variables that start with azmt
represent the azimuth of each side of the polygon, however I did not do it in the most intelligent way, because the code only runs for this specific file ("drawing.txt").
I would like the program to work for other ". txt" files as well (of course, provided this file provides the necessary instructions). I’ve been told that I could automate this part of the code using a loop like for
, but it didn’t work out at all. Someone can 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()
What is the file format
desenho.txt
? And what would be the formats of the other files?– Woss