Files
@ c96bd773ec28
Branch filter:
Location: OneEye/exp/diagram.py - annotation
c96bd773ec28
940 B
text/x-python
random image transformations
6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f 6180b3bd7f3f | import PIL.Image
import PIL.ImageDraw
width=360
height=width
padding=12
stoneSize=(width-2*padding)/18
yellow=(255,200,0)
white=(255,255,255)
black=(0,0,0)
def createDiagram(board):
img=PIL.Image.new("RGB",(width,height),yellow)
canvas=PIL.ImageDraw.Draw(img)
# grid
for i in range(19):
canvas.line((padding,padding+i*stoneSize,width-padding,padding+i*stoneSize),black,1)
canvas.line((padding+i*stoneSize,padding,padding+i*stoneSize,height-padding),black,1)
# stars
radius=2
for r in range(3,19,6):
for c in range(3,19,6):
x=c*stoneSize+padding
y=r*stoneSize+padding
canvas.ellipse((x-radius,y-radius,x+radius,y+radius),black)
# stones
radius=stoneSize/2
for (r,row) in enumerate(board):
for (c,color) in enumerate(row):
if color=="X" or color=="O":
x=c*stoneSize+padding
y=r*stoneSize+padding
canvas.ellipse((x-radius,y-radius,x+radius,y+radius),black if color=="X" else white)
return img
|