gilesknap / mciwb

Minecraft Interactive world builder
Apache License 2.0
301 stars 6 forks source link

Would you be interested in a chapter about drawing image? #107

Open jhutar opened 1 year ago

jhutar commented 1 year ago

Hello. We created this to "draw" image from file in Minecraft as a wall:

image

Would you be interested in a chapter to the doc describing that code?

import PIL.Image
im = PIL.Image.open("cat.png")
im = im.resize((20, 20))

def decide_black_or_white(x):
     if x > 50:
         return 255
     else:
         return 0

im = im.convert('L').point(decide_black_or_white, mode='1')
pixel_map = im.load()

pos = world.player.pos

def draw_pixel(position, x):
    world = get_world()
    if x == 255:
        material = Item.BLACK_CONCRETE
    else:
        material = Item.WHITE_CONCRETE
    world.set_block(position, material)

for row in range(20):
    for column in range(20):
        draw_pixel(pos + Direction.UP * (20 - 1) + Direction.DOWN * row + Direction.SOUTH * column, pixel_map[column, row])

That code needs a bit of work, but something like this worked for us. IIRC the screenshot is from different image, it was 100 x 100.

gilesknap commented 1 year ago

Wow, that is the kind of thing I hoped people would make with MCIWB!

It's a great idea well executed.

I would love to get your contribution to the project. I suggest you add it as an additional tutorial after the (as yet unwritten) Moving Structures.