naeem043

Python MPL

Oct 31st, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. # Python3 program for Mid-point
  2. # line generation
  3.  
  4.  
  5. # midPoint function for line generation
  6. def midPoint(X1,Y1,X2,Y2):
  7.     # calculate dx & dy
  8.     dx = X2 - X1
  9.     dy = Y2 - Y1
  10.  
  11.     # initial value of decision parameter d
  12.     d = dy - (dx/2)
  13.     x = X1
  14.     y = Y1
  15.  
  16.     # Plot initial given point
  17.     # putpixel(x,y) can be used to print pixel
  18.     # of line in graphics
  19.     print('The points are (x,y) (', x,', ', y,')')
  20.     # iterate through value of X
  21.     while (x < X2):
  22.         x=x+1
  23.         # E or East is chosen
  24.         if(d < 0):
  25.             d = d + dy
  26.  
  27.         # NE or North East is chosen
  28.         else:
  29.             d = d + (dy - dx)
  30.             y=y+1
  31.    
  32.  
  33.         # Plot intermediate points
  34.         # putpixel(x,y) is used to print pixel
  35.         # of line in graphics
  36.         print('The points are (x,y) (', x,', ', y,')')
  37.    
  38.  
  39. # Driver program
  40.  
  41. if __name__=='__main__':
  42.     X1 = int(input("Enter Start X: "))
  43.     Y1 = int(input("Enter Start Y: "))
  44.     X2 = int(input("Enter End X: "))
  45.     Y2 = int(input("Enter End Y: "))
  46.     midPoint(X1, Y1, X2, Y2)
  47.    
  48.    
  49. a = input('Press any key to exit')
  50.  
  51. # This code is contributed by ash264
Advertisement
Add Comment
Please, Sign In to add comment