Что использовать для конечных координат x, y в addLine с использованием списка

мне нужно нарисовать линию между несколькими городами, используя добавить линию. Координаты городов берутся из списка. Однако я не знаю, как мне ввести конечные координаты. Вот код до сих пор:

def a2level1():
  cityXCoordinate=[ 43, 93,180,205,254,310,326,348,372,398]
  cityYCoordinate=[308,145, 82,199,335,373,432,346,333,263]

  map = makePicture()
  show(map)
  cities =  [requestInteger("Enter the number of cities you would like to visit")]
  for number in cities:
    print number
    for number in range(0,number):
      print number
      city = [requestInteger("Please choose a city number")]
      while city <= number:
          city = [requestInteger("Please choose a city number")]
          addLine(map,cityXCoordinate[city],cityYCoordinate[city], cityXCoordinate[city], cityYCoordinate[city])


  repaint(map)

person madsy84    schedule 21.01.2014    source источник


Ответы (1)


Я называю координаты x и y для двух городов отдельно и уменьшаю их для удобства чтения:

#addLine(map,cityXCoordinate[city],cityYCoordinate[city],
#cityXCoordinate[city], cityYCoordinate[city])

cityXCoordinate1= x1
cityYCoordinate1 = y1
cityXCoordinate2 = x2
cityYCoordinate2 = y2

В этом случае я не перерисовываю изображение, а создаю второе изображение, чтобы первое не перезаписывалось, это ваш выбор.

#Find the max height and width of your map
w= getWidth (map)
h = getHeight(map)
newPic = makeEmptyPicture(w,h)

#loop through the coordinates of the map
for y in range (0,h):
  for x in range (0, w):

  #select the points forming a straight line between the two points
  if (x==((y-y1)*(x2-x1)/(y2-y1)+x1)):
    newPxl= getPixel(newPic,x,y)
    #color those pixels black
    color = makeColor(0,0,0)
    setColor (newPxl, color)
  else:
    #color the remaining map as it is
    pxl = getPixel(pic, x, y)
    newPxl= getPixel(newPic,x,y)
    color = getColor(pxl)
    setColor (newPxl, color)
person Community    schedule 26.01.2014