SHARE
TWEET

Untitled

a guest Dec 12th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top