Commit 7c6a7fdb authored by Nathan/Eilisha Shiraini's avatar Nathan/Eilisha Shiraini
Browse files

Implemented the image drawing package

parent cd6b3554
from PIL import Image
def _sumtuple(*t):
return tuple(sum(i) for i in zip(*t))
except TypeError:
return sum(t)
class ImGenerator(object):
def __init__(self, data, interpolation, imageMode, modSize, quietZone = 1):
self.interpolation = interpolation.value = data
self.quietZone = quietZone
self.qzColor = _sumtuple(i[0] for i in self.interpolation)
self.dataSize = data[0].shape[0]
self.modSize = modSize
self.imageSize = (modSize * (quietZone * 2 + self.dataSize),) * 2
self.image =, self.imageSize)
def moduleColor(self, modX, modY):
if modX not in range(self.quietZone, self.quietZone + self.dataSize):
return self.qzColor
if modY not in range(self.quietZone, self.quietZone + self.dataSize):
return self.qzColor
return _sumtuple(self.interpolation[i][1 if data[modY - self.quietZone, modX - self.quietZone] else 0] for i, data in enumerate(
def moduleCoordinates(self, modX, modY):
for i in range(self.modSize):
for j in range(self.modSize):
yield (j + modX * self.modSize, i + modY * self.modSize)
def moduleRect(self, modX, modY):
return [modX * self.modSize, modY * self.modSize, (modX + 1) * self.modSize, (modY + 1) * self.modSize,]
def drawModule(self, modX, modY):
color = self.moduleColor(modX, modY)
for coords in self.moduleCoordinates(modX, modY):
self.image.putpixel(coords, color)
def drawCode(self):
size = self.quietZone * 2 + self.dataSize
for y in range(size):
for x in range(size):
self.drawModule(x, y)
def saveImage(self, fname, *args, **kwargs):, *args, **kwargs)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment