naeem043

pydda

Jan 2nd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import sys, pygame
  2. from pygame import gfxdraw
  3.  
  4. pygame.init()
  5. screen = pygame.display.set_mode((400,400))
  6. screen.fill((0,0,0))
  7. pygame.display.flip()
  8.  
  9. white=(255,255,255)
  10.  
  11. def ROUND(n):
  12.     return int(n+0.5)
  13.  
  14. def dda(x1,y1,x2,y2):
  15.     x,y = x1,y1
  16.     length = (x2-x1) if (x2-x1) > (y2-y1) else (y2-y1)
  17.     dx = (x2-x1)/float(length)
  18.     dy = (y2-y1)/float(length)
  19.    
  20.     gfxdraw.pixel(screen,ROUND(x),ROUND(y),white)
  21.  
  22.     for i in range(length):
  23.         x+= dx
  24.         y+= dy
  25.         print('The points are (x,y) (', x,', ', y,')')
  26.         gfxdraw.pixel(screen,ROUND(x),ROUND(y),white)
  27.     pygame.display.flip()
  28.  
  29. x1 = int(input('Enter the x1 point: '))
  30. y1 = int(input('Enter the y1 point: '))
  31. x2 = int(input('Enter the x2 point: '))
  32. y2 = int(input('Enter the y2 point: '))
  33.  
  34. dda(x1, y1, x2, y2)
  35.  
  36. while 1:
  37.     for event in pygame.event.get():
  38.         if event.type == pygame.QUIT: sys.exit()
  39.  
  40.  
  41. # a = input('Press any key to exit')
Add Comment
Please, Sign In to add comment