Example #1
0
 def create_tv(self):
     o = self.origin
     self.world.blocks[o:o + self.size + 1] = Block('#ffffff')
     self.world.blocks[o + V(0, 1, 1):o + self.size - V(0, 1, 1) +
                       1] = Block('#000000')
     self.button_vec = o + V(z=2)
     self.world.blocks[self.button_vec] = Block('#800000')
Example #2
0
 def create_tv(self):
     o = self.origin
     self.world.blocks[o:o + self.size + 1] = Block('#ffffff')
     self.world.blocks[o + V(0, 1, 1):o + self.size - V(0, 2, 2) +
                       1] = Block('#000000')
     self.button_pos = o + V(z=3)
     self.quit_pos = o + V(z=1)
     self.world.blocks[self.button_pos] = Block('#0080ff')
     self.world.blocks[self.quit_pos] = Block('#800000')
     self.world.say('Behold the Minecraft TV!')
Example #3
0
 def __init__(self, origin=V(), size=(12, 8)):
     self.camera = picamera.PiCamera()
     self.camera.resolution = (64, int(64 / size[0] * size[1]))
     self.camera.framerate = 2
     self.world = World(ignore_errors=True)
     self.origin = origin
     self.size = V(0, size[1], size[0])
     self.button_vec = None
     self.screen = MinecraftTVScreen(self.world, origin + V(0, 1, 1),
                                     (size[0] - 2, size[1] - 2))
Example #4
0
 def __init__(self, world, origin=V(), size=(12, 8)):
     self.world = world
     self.camera = picamera.PiCamera()
     self.camera.resolution = (64, int(64 / size[0] * size[1]))
     self.camera.framerate = 5
     self.origin = origin
     self.size = V(0, size[1], size[0])
     self.button_pos = None
     self.quit_pos = None
     self.screen = MinecraftTVScreen(self.world, origin + V(0, 1, 1),
                                     (size[0] - 2, size[1] - 2))
Example #5
0
 def render(self, jpeg):
     o = self.origin
     img = Image.open(jpeg)
     img = img.resize(self.size, Image.BILINEAR)
     img = img.quantize(self.palette_len, palette=self.palette)
     with self.world.connection.batch_start():
         for x in range(img.size[0]):
             for y in range(img.size[1]):
                 self.world.blocks[o + V(0, y, x)] = Block.from_id(
                     35, img.getpixel((x, y)))
Example #6
0
 def render(self, jpeg):
     o = self.origin
     img = Image.open(jpeg)
     img = img.resize(self.size, Image.BILINEAR)
     img = img.quantize(len(self.palette), palette=self.palette_img)
     new_state = {
         o + V(0, y, x): Block.from_color(self.palette[img.getpixel(
             (x, y))],
                                          exact=True)
         for x in range(img.size[0]) for y in range(img.size[1])
     }
     with self.world.connection.batch_start():
         for v, b in track_changes(self.state, new_state).items():
             self.world.blocks[v] = b
     self.state = new_state
Example #7
0
def test_vector_sphere():
    assert set(sphere(O, 1)) == {-X, X, -Y, Y, -Z, Z}
    # Yeah, it's a pre-calculated test ... oh well
    assert set(sphere(O, 2)) == {
        V(-2, -1, 0),
        V(-2, 0, -1),
        V(-2, 0, 0),
        V(-2, 0, 1),
        V(-2, 1, 0),
        V(-1, -2, 0),
        V(-1, -1, -1),
        V(-1, -1, 0),
        V(-1, -1, 1),
        V(-1, 0, -2),
        V(-1, 0, -1),
        V(-1, 0, 1),
        V(-1, 0, 2),
        V(-1, 1, -1),
        V(-1, 1, 0),
        V(-1, 1, 1),
        V(-1, 2, 0),
        V(0, -2, -1),
        V(0, -2, 0),
        V(0, -2, 1),
        V(0, -1, -2),
        V(0, -1, -1),
        V(0, -1, 1),
        V(0, -1, 2),
        V(0, 0, -2),
        V(0, 0, 2),
        V(0, 1, -2),
        V(0, 1, -1),
        V(0, 1, 1),
        V(0, 1, 2),
        V(0, 2, -1),
        V(0, 2, 0),
        V(0, 2, 1),
        V(1, -2, 0),
        V(1, -1, -1),
        V(1, -1, 0),
        V(1, -1, 1),
        V(1, 0, -2),
        V(1, 0, -1),
        V(1, 0, 1),
        V(1, 0, 2),
        V(1, 1, -1),
        V(1, 1, 0),
        V(1, 1, 1),
        V(1, 2, 0),
        V(2, -1, 0),
        V(2, 0, -1),
        V(2, 0, 0),
        V(2, 0, 1),
        V(2, 1, 0)
    }
Example #8
0
 def switch_off(self):
     self.world.say('Switching TV off')
     self.camera.stop_recording()
     o = self.origin
     self.world.blocks[o + V(0, 1, 1):o + self.size - V(0, 2, 2) +
                       1] = Block('#000000')
Example #9
0
                time.sleep(0.1)
        finally:
            if self.camera.recording:
                self.switch_off()
            self.destroy_tv()

    def create_tv(self):
        o = self.origin
        self.world.blocks[o:o + self.size + 1] = Block('#ffffff')
        self.world.blocks[o + V(0, 1, 1):o + self.size - V(0, 1, 1) +
                          1] = Block('#000000')
        self.button_vec = o + V(z=2)
        self.world.blocks[self.button_vec] = Block('#800000')

    def destroy_tv(self):
        o = self.origin
        self.world.blocks[o:o + self.size + 1] = Block('air')

    def switch_on(self):
        self.camera.start_recording(self.screen, format='mjpeg')

    def switch_off(self):
        self.camera.stop_recording()
        o = self.origin
        self.world.blocks[o + V(0, 1, 1):o + self.size - V(0, 2, 2) +
                          1] = Block('#000000')


tv = MinecraftTV(origin=V(2, 0, 5), size=(24, 16))
tv.main_loop()