img2.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import PIL
  2. import PIL.Image
  3. import os
  4. import time
  5. import pygame
  6. pg = pygame
  7. class IMG():
  8. def __init__(self,w=300,h=200,color=[255,0,0]):
  9. self.w = w
  10. self.h = h
  11. img = PIL.Image.new("RGB", (w, h))
  12. pixels = (color[0],color[1],color[2])*(w*h)
  13. img.putdata(pixels)
  14. def draw(self,x=10,y=10,b=10,w=10):
  15. img = PIL.Image.new("RGB", (200, 200))
  16. #img.show() # see a black image
  17. pixels = [(255,0,0)]*(200*200)
  18. for i in range(10):
  19. x = (i+20)* (200 )
  20. print(pixels[x])
  21. for j in range(10):
  22. y = j +10
  23. pixels[x+y] = (255,255,255)
  24. img.putdata(pixels)
  25. self.img = img
  26. def get(self):
  27. t = self.img.tobytes()
  28. s = self.img.size
  29. m = self.img.mode
  30. out = pygame.image.fromstring( t,s,m).convert()
  31. return out
  32. img = IMG()
  33. pygame.init()
  34. main_size=(600,300)
  35. window = pygame.display.set_mode(main_size,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  36. #window = pygame.display.set_mode(main_size,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  37. pg.display.set_caption('LibreLight PIL')
  38. img.draw()
  39. pygameSurface = img.get()
  40. run = True
  41. while run:
  42. #pg.clock.tick(60)
  43. for event in pygame.event.get():
  44. if event.type == pygame.QUIT:
  45. run = False
  46. window.fill(0)
  47. window.blit(pygameSurface, pygameSurface.get_rect(center = (150, 150)))
  48. pygame.display.flip()
  49. exit()