Doing an assignment for uni and I am baffled. I know it must be something simple but for the life of me I cannot get the function mapLevel2
to use the result of getDistanceBetween
in an addText
.
I know the code would be better in a loop and that is the next step after this, but I need to get this code working first.
def mapLevel2():
map=makePicture("C:/Users/Shaun/Documents/CPT120/Assignment 2/map.png")
cityXvalue= [ 45,95,182,207,256,312,328,350,374,400 ]
cityYvalue= [ 310,147,84,201,337,375,434,348,335,265 ]
writePictureTo(map,"C:/Users/Shaun/Documents/CPT120/Assignment 2/marked-map.png")
show (map)
stops=requestInteger ("How many places would you like to visit?")
if stops==2:
start=requestInteger ("Where would you like to start your trip?")
second= requestInteger ("What is the number of the next place you would like to visit")
addLine(map,cityXvalue[start],cityYvalue[start],cityXvalue[second],cityYvalue[second])
KMs=getDistanceBetween(cityXvalue[start],cityYvalue[start],cityXvalue[second],cityYvalue[second])
addText(map,21,34,KMs)
writePictureTo(map,"C:/Users/Shaun/Documents/CPT120/Assignment 2/marked-map.png")
repaint (map)
def getDistanceBetween(x1,y1,x2,y2):
dist=sqrt(pow(x1-x2,2)+pow(y1-y2,2))
KMs=dist*10
return KMs
Thanks for any help you can give me.