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)
You appear to have infringed my copyright without giving proper attribution.
ReplyDeletePlease see http://www.themagpi.com/issue/issue-27/ based on code I wrote in August 2014.
Like I say not new or original. A very different implementation from the one in the magpi tho.
DeleteHi Martin, I love what you've done with this...permission to use this in schools?
DeleteAlso, I too have received the 'copyright infringement' message from Dougie Lawson. I have since sent him proof of my work making QR Codes in Minecraft from over two years ago as well as a video showcasing that work and published in mid 2013. What disturbs and disappoints me most is the method in which he has chosen to challenge us. Commenting directly onto a blog post can be damaging and shake the trust of our readers. I asked him kindly to send a mail or make a phone call should he require any more contact.
Should you yourself require the evidence of my work in this area, going back two years, please just ask. Since your work is inspired by my work and while my permission is not necessary, please be assured you have my full permission and support.
Stephen Reid - ImmersiveMind
Thanks a lot Stephen. Of course you have my permission, its very nice of you to ask.
DeleteI originally thought Dougie Lawson was being sarcastic, such is my generally positive view of people and their attitudes, clearly wrong this time though!
Perhaps Dougie should be asking for your attribution?
Hi Martin,
ReplyDeleteI've written the code exactly as above, but keep getting the error:
Traceback (most recent call last):
File "/home/pi/qrcode.py", line 1, in
from qrcode import *
File "/home/pi/qrcode.py", line 14, in
qrMatrix = getQR("Minecraft is Awesome!")
File "/home/pi/qrcode.py", line 6, in getQR
qr = QRCode(version=1, error_correction=ERROR_CORRECT_L, border=1)
NameError: global name 'QRCode' is not defined
Any idea why?
I think its because you have saved your program as qrcode.py, python is getting confused because you are trying to import a module which is also called qrcode...
DeleteYou should save you program as something else and delete the qrcode.py and qrcode.pyc files.