Point your phone at this...
That afternoon I had 30 minutes to wait before I was picked up to be taken out for festive activities - could I code a Minecraft QR generator in time? It turns out I could:
I used the fantastic python module qrcode to create the QR, which has a useful function, get_matrix(), to allow you to get the QR as a 2 dimensional list of True and False's. I then used this matrix to create white and black wool - dead easy!
The qrcode module can be installed using pip and requires PIL (python imaging library) to work - the first step is to install pip and PIL and then use pip to install qrcode:
sudo apt-get install python-pip python-imaging sudo pip install qrcodeYou can get the code from github:
git clone https://github.com/martinohanlon/minecraft-qrcodeRun it:
python minecraft-qrcode/minecraft-qrcode.pyThe code:
from qrcode import * from mcpi.minecraft import * from mcpi.block import * def getQR(inputString): qr = QRCode(version=1, error_correction=ERROR_CORRECT_L, border=1) qr.add_data(inputString) qr.make() return qr.get_matrix() mc = Minecraft.create() pos = mc.player.getTilePos() qrMatrix = getQR("http://www.stuffaboutcode.com") rowNo = 0 for row in qrMatrix: rowNo -= 1 columnNo = 0 for column in row: columnNo -= 1 if column: #black blockColour = 15 else: #white blockColour = 0 mc.setBlock(pos.x + rowNo, pos.y + columnNo, pos.z, WOOL.id, blockColour)