Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. from PIL import Image, ImageDraw
  2. import random
  3.  
  4. def board(dimension, pixel_size):
  5. board_color = (255, 255, 255)
  6. w = dimension * pixel_size
  7. image = Image.new('RGB', (w, w), board_color)
  8. draw = ImageDraw.Draw(image)
  9. for i in range(dimension):
  10. for j in range(dimension):
  11. r = random.randint(0, 256)
  12. g = random.randint(0, 256)
  13. b = random.randint(0, 256)
  14. shape = [(i * pixel_size, j * pixel_size), ((i + 1) * pixel_size, (j + 1) * pixel_size)]
  15. draw.rectangle(shape, fill=(r, g, b))
  16. image.save('chess.png', 'PNG')
  17. image.show()
  18.  
  19.  
  20. board(8, 50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement