test.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/python3
  2. import sys,os
  3. os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
  4. import pygame
  5. from pygame.locals import *
  6. os.environ["SDL_FBDEV"] = "/dev/fb1"
  7. # Uncomment if you have a touch panel and find the X value for your device
  8. #os.environ["SDL_MOUSEDRV"] = "TSLIB"
  9. #os.environ["SDL_MOUSEDEV"] = "/dev/input/eventX"
  10. pygame.init()
  11. # set up the window
  12. DISPLAYSURF = pygame.display.set_mode((128, 160), 0, 32)
  13. pygame.display.set_caption('Drawing')
  14. # set up the colors
  15. BLACK = ( 0, 0, 0)
  16. WHITE = (255, 255, 255)
  17. RED = (255, 0, 0)
  18. GREEN = ( 0, 255, 0)
  19. BLUE = ( 0, 0, 255)
  20. # draw on the surface object
  21. DISPLAYSURF.fill(WHITE)
  22. pygame.draw.polygon(DISPLAYSURF, GREEN, ((16, 0), (111, 106), (36, 277), (56, 27), (0, 106)))
  23. pygame.draw.line(DISPLAYSURF, BLUE, (60, 60), (120, 60), 4)
  24. pygame.draw.line(DISPLAYSURF, BLUE, (120, 60), (60, 120))
  25. pygame.draw.line(DISPLAYSURF, BLUE, (60, 120), (120, 120), 4)
  26. pygame.draw.circle(DISPLAYSURF, BLUE, (40, 50), 20, 0)
  27. pygame.draw.ellipse(DISPLAYSURF, RED, (110, 200, 40, 80), 1)
  28. box = pygame.draw.rect(DISPLAYSURF, RED, (100, 150, 100, 50))
  29. pixObj = pygame.PixelArray(DISPLAYSURF)
  30. pixObj[120][144] = BLACK
  31. pixObj[122][146] = BLACK
  32. pixObj[124][148] = BLACK
  33. pixObj[126][158] = BLACK
  34. pixObj[126][158] = BLACK
  35. del pixObj
  36. # run the game loop
  37. while True:
  38. for event in pygame.event.get():
  39. if event.type == QUIT:
  40. pygame.quit()
  41. sys.exit()
  42. if event.type == pygame.MOUSEBUTTONDOWN:
  43. print("Pos: %sx%s\n" % pygame.mouse.get_pos())
  44. if box.collidepoint(pygame.mouse.get_pos()):
  45. pygame.quit()
  46. sys.exit()
  47. pygame.display.update()