Created
February 17, 2020 19:15
-
-
Save travis-g/dd2028f18ffb7de76f892f789a6a5eab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import json | |
import requests | |
h = 1000 | |
w = 1000 | |
# PIL accesses images in Cartesian co-ordinates, so it is Image[columns, rows] | |
img = Image.new( 'RGB', (h,w), "black") # create a new black image | |
pixels = img.load() # create the pixel map | |
black = 0 | |
white = 0 | |
total = h*w | |
with requests.Session() as s: | |
for i in range(img.size[0]): # for every col: | |
for j in range(img.size[1]): # For every row | |
response = s.get('http://localhost:6436/roll/d2') | |
obj = json.loads(response.text) | |
val = obj['dice']['group'][0]['result']['value'] | |
if val == 1: | |
black+=1 | |
pixels[i,j] = (0, 0, 0) # set the colour accordingly | |
elif val == 2: | |
white+=1 | |
pixels[i,j] = (255,255,255) | |
else: | |
print("BAD ERROR") | |
print("black: {}".format(black/total)) | |
print("white: {}".format(white/total)) | |
# img.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment