Ejemplo n.º 1
0
    def test_image_files(self):
        """
        Check that the ImageFile renderer works.
        """
        renderer = ImageFile(os.path.join(os.path.dirname(__file__),
                                          "globe.gif"),
                             height=10)

        # Check renderer got all images from the file.
        count = 0
        for image in renderer.images:
            count += 1
            self.assertIsNotNone(image)
            self.assertIsNotNone(len(image) <= renderer.max_height)
        self.assertEqual(count, 11)

        # Check an image looks plausible
        image = next(renderer.images)
        self.assertEqual(image, [
            '', '        .:;rA       ', '    :2HG#;H2;s;;2   ',
            '  .::#99&G@@hsr;;s3 ', ' .:;;9&@@@Hrssrrr;22',
            's.:;;;@Hs2GArsssrrr#', '..:;;;rrsGA&&Gsrrr;r',
            ' .:;;;;rsr@@@@@@Hs;:', ' ;.:;;;;rrA@@@@@G;: ',
            '   .::;;;;;2&9G:;:  ', '     ..:::;Gr::s    '
        ])
Ejemplo n.º 2
0
def art():
    # generate a planet graphic
    planet()
    size = random.randint(10, 20)
    screen = Screen.open(None)
    effects = [
        PrintInSpace(
            screen,
            ImageFile('./tmp/planet.png', size, screen.height / 2 - size / 2),
            (screen.width + screen.height) // 4),
    ]
    screen.set_scenes([Scene(effects, 500)])
    for i in range(0, 10):
        screen.draw_next_frame()
    # screen.play([Scene(effects, duration=5, clear=False)], repeat=False)
    # print(screen)
    # print(screen.dimensions)
    doc = ""
    for y in range(0, screen.dimensions[0]):
        doc += "\n"
        for x in range(0, screen.dimensions[1]):
            code = screen.get_from(x, y)  # returns a tuple, ascii = 0
            # if code is not None:
            doc += chr(code[0])
    f = open("./tmp/planet.txt", "w")
    f.write(doc)
    screen.close(True)
    f.close()
Ejemplo n.º 3
0
    def test_image_files(self):
        """
        Check that the ImageFile renderer works.
        """
        renderer = ImageFile(os.path.join(os.path.dirname(__file__),
                                          "globe.gif"),
                             height=10)

        # Check renderer got all images from the file.
        count = 0
        for image in renderer.images:
            count += 1
            self.assertIsNotNone(image)
            self.assertIsNotNone(len(image) <= renderer.max_height)
        self.assertEqual(count, 11)

        # Check an image looks plausible
        image = next(renderer.images)
        self.maxDiff = None
        self.assertEqual(image, [
            '', '     sA3h3h3Hr2     ', '  ;:;G#99G@&2;;;r   ',
            ' .::#9&&@@G;rrrr;;3 ', '.:;;A&@AAGsssssrr;#H',
            '.:;;;r29@srssssrr;A2', '.::;;rrrrr@@@@9;r;;A',
            's.:;;;;rr2@@@@@@#;; ', ' s.::;;;;;;9&&&3;:  ',
            '   ..::;;;;9#r::2   ', '      s...r.;       '
        ])
Ejemplo n.º 4
0
def animation(screen):
    # generate a planet graphic
    planet()
    size = random.randint(10, 20)
    effects = [
        PrintInSpace(screen, ImageFile('./tmp/planet.png', size),
                     (screen.width + screen.height) // 4),
    ]
    screen.play([Scene(effects, 500)])
Ejemplo n.º 5
0
def demo(screen):
    scenes = []

    effects = [
            Print(screen, ImageFile("/home/pi/Desktop/WASP-Emojis-master/images/smiling.jpg", screen.height - 2, colours=screen.colours),
                  0,
                  stop_frame=100),
        ]
    scenes.append(Scene(effects))

    screen.play(scenes, stop_on_resize=True)
Ejemplo n.º 6
0
	def gray(self, screen = None, file = None,):
		if file == None:
			file = self.imgs[0]

		scenes = []
		effects = [
			Print(screen,
				ImageFile(file, screen.height, colours = screen.colours),
				screen.height),
			Scroll(screen, 2)
		]
		scenes.append(Scene(effects))
		screen.play(scenes)
Ejemplo n.º 7
0
def demo(screen):
    scenes = []
    effects = [
        Print(screen,
              ImageFile("globe.gif", screen.height - 2,
                        colours=screen.colours),
              0,
              stop_frame=100),
    ]
    scenes.append(Scene(effects))
    effects = [
        Print(screen,
              ColourImageFile(screen,
                              "colour_globe.gif",
                              screen.height - 2,
                              uni=screen.unicode_aware,
                              dither=screen.unicode_aware),
              0,
              stop_frame=200),
        Print(screen,
              FigletText("ASCIIMATICS",
                         font='banner3' if screen.width > 80 else 'banner'),
              screen.height // 2 - 3,
              colour=7,
              bg=7 if screen.unicode_aware else 0),
    ]
    scenes.append(Scene(effects))
    effects = [
        Print(screen,
              ColourImageFile(screen,
                              "grumpy_cat.jpg",
                              screen.height,
                              uni=screen.unicode_aware),
              screen.height,
              speed=1,
              stop_frame=(40 + screen.height) * 3),
        Scroll(screen, 3)
    ]
    scenes.append(Scene(effects))
    effects = [
        BannerText(
            screen,
            ColourImageFile(screen,
                            "python.png",
                            screen.height - 2,
                            uni=screen.unicode_aware,
                            dither=screen.unicode_aware), 0, 0),
    ]
    scenes.append(Scene(effects))

    screen.play(scenes, stop_on_resize=True)
Ejemplo n.º 8
0
def main(screen, args):

    os.environ['GYM_NEYBOY_OBS_AS_BYTES'] = '1'
    del os.environ['GYM_NEYBOY_ENV_NON_HEADLESS']

    env = gym.make(args.env)
    total_reward = 0
    total_steps = 0
    while True:
        total_steps += 1
        ev = screen.get_key()
        action = 0

        if ev in (Screen.KEY_LEFT, ord('A'), ord('a')):
            action = 1
        elif ev in (Screen.KEY_RIGHT, ord('D'), ord('d')):
            action = 2
        elif ev in (Screen.KEY_UP, ord('W'), ord('w')):
            env.reset()
        elif ev in (Screen.KEY_ESCAPE, ord('Q'), ord('q')):
            env.close()
            break

        observation, reward, done, info = env.step(action)
        total_reward += reward

        if args.color:
            renderer = ColourImageFile(screen, observation, height=args.height)
        else:
            renderer = ImageFile(observation,
                                 height=args.height,
                                 colours=screen.colours)

        image, colours = renderer.rendered_text
        for (i, line) in enumerate(image):
            screen.centre(line, i, colour_map=colours[i])

        screen.print_at('{0:.2f}'.format(reward), 0, 0)
        screen.print_at('{0:.2f}'.format(total_reward), 0, 1)
        screen.print_at('done: {}'.format(done), 0, 2)

        screen.refresh()
Ejemplo n.º 9
0
def demo(screen):
    scenes = []

    effects = [
        Print(screen,
              ImageFile("/home/pi/Desktop/WASP-Emojis-master/images/image.jpg",
                        screen.height - 2,
                        colours=screen.colours),
              0,
              stop_frame=100),
        Print(screen,
              FigletText("H E R M E S",
                         font='epic' if screen.width > 80 else 'banner'),
              screen.height // 2 - 3,
              colour=7,
              bg=7 if screen.unicode_aware else 0),
    ]
    scenes.append(Scene(effects))

    screen.play(scenes, stop_on_resize=True)
Ejemplo n.º 10
0
def main(screen, args):
    home_dir = Path.home()
    data_dir = Path(home_dir, 'flappybird')
    data_dir.mkdir(exist_ok=True)

    game = SyncFlappyBird.create(headless=not args.non_headless,
                                 user_data_dir=str(data_dir))
    game.load()

    while True:
        state = game.get_state(include_snapshot='bytes')
        ev = screen.get_key()
        if ev in (Screen.KEY_LEFT, ord('A'), ord('a'), Screen.KEY_RIGHT,
                  ord('D'), ord('d')):
            game.tap()
        elif ev in (Screen.KEY_UP, ord('W'), ord('w')):
            game.restart()
        elif ev in (ord('P'), ord('p')):
            if game.is_paused():
                game.resume()
            else:
                game.pause()
        elif ev in (Screen.KEY_ESCAPE, ord('Q'), ord('q')):
            game.stop()
            break

        if args.color:
            renderer = ColourImageFile(screen,
                                       state.snapshot,
                                       height=args.height)
        else:
            renderer = ImageFile(state.snapshot,
                                 height=args.height,
                                 colours=screen.colours)

        image, colours = renderer.rendered_text
        for (i, line) in enumerate(image):
            screen.centre(line, i, colour_map=colours[i])
            # screen.paint(line, 0, i, colour_map=colours[i], transparent=False)
        screen.refresh()
Ejemplo n.º 11
0
def load_image(opt, path):
    mode = opt.get('image_mode', 'raw')
    if mode is None or mode == 'none':
        # don't need to load images
        return None
    elif mode == 'raw':
        # raw just returns RGB values
        return Image.open(path).convert('RGB')
    elif mode == 'ascii':
        # convert images to ascii ¯\_(ツ)_/¯
        return str(ImageFile(path, height=30))
    else:
        # otherwise, looks for preprocessed version under 'mode' directory
        prepath, imagefn = os.path.split(path)
        new_path = os.path.join(prepath, mode, imagefn)
        if not os.path.isfile(new_path):
            # currently only supports *downloaded* preprocessing
            # TODO: generate preprocessed images if not available
            raise NotImplementedError('image preprocessing mode' +
                                      '{} not supported yet'.format(mode))
        else:
            return Image.open(path)
Ejemplo n.º 12
0
def _credits(screen):
    scenes = []
    centre = (screen.width // 2, screen.height // 2)
    curve_path = []
    for i in range(0, 11):
        curve_path.append(
            (centre[0] + (screen.width / 3 * math.sin(i * math.pi / 5)),
             centre[1] - (screen.height / 3 * math.cos(i * math.pi / 5))))
    path = Path()
    path.jump_to(-20, centre[1] - screen.height // 3)
    path.move_straight_to(centre[0], centre[1] - screen.height // 3, 10),
    path.wait(30)
    path.move_round_to(curve_path, 80)
    path.wait(30)
    path.move_straight_to(7, 4, 10)
    path.wait(300)

    effects = [
        Sam(screen, path),
        Print(screen,
              SpeechBubble("WELCOME TO ASCIIMATICS", "L"),
              x=centre[0] + 12,
              y=(centre[1] - screen.height // 3) - 4,
              colour=Screen.COLOUR_CYAN,
              clear=True,
              start_frame=20,
              stop_frame=50),
        Print(screen,
              SpeechBubble("Wheeeeeee!"),
              y=centre[1],
              colour=Screen.COLOUR_CYAN,
              clear=True,
              start_frame=100,
              stop_frame=250),
        Print(screen,
              SpeechBubble("A world of possibilities awaits you...", "L"),
              x=18,
              y=0,
              colour=Screen.COLOUR_CYAN,
              clear=True,
              start_frame=350,
              stop_frame=400),
        Print(screen,
              ImageFile("globe.gif", colours=screen.colours),
              0,
              start_frame=400),
    ]
    scenes.append(Scene(effects, 600))

    effects = [
        Matrix(screen, stop_frame=200),
        Mirage(screen,
               FigletText("Asciimatics"),
               screen.height // 2 - 3,
               Screen.COLOUR_GREEN,
               start_frame=100,
               stop_frame=200),
        Wipe(screen, start_frame=150),
        Cycle(screen,
              FigletText("Asciimatics"),
              screen.height // 2 - 3,
              start_frame=200)
    ]
    scenes.append(Scene(effects, 250, clear=False))

    effects = [
        BannerText(
            screen,
            Rainbow(
                screen,
                FigletText("Reliving the 80s in glorious ASCII text...",
                           font='slant')), screen.height // 2 - 3,
            Screen.COLOUR_GREEN)
    ]
    scenes.append(Scene(effects))

    effects = [
        Mirage(screen, FigletText("Conceived and"), screen.height,
               Screen.COLOUR_GREEN),
        Mirage(screen, FigletText("written by:"), screen.height + 8,
               Screen.COLOUR_GREEN),
        Mirage(screen, FigletText("Peter Brittain"), screen.height + 16,
               Screen.COLOUR_GREEN),
        Scroll(screen, 3)
    ]
    scenes.append(Scene(effects, (screen.height + 24) * 3))

    effects = [
        Cycle(screen, FigletText("ASCIIMATICS", font='big'),
              screen.height // 2 - 8),
        Cycle(screen, FigletText("ROCKS!", font='big'),
              screen.height // 2 + 3),
        Stars(screen, (screen.width + screen.height) // 2)
    ]
    scenes.append(Scene(effects, 200))

    screen.play(scenes, stop_on_resize=True)
Ejemplo n.º 13
0
def main():
    metadata = {}
    fi = sys.stdin
    while True:
        line = sys.stdin.readline()
        if not line:  #EOF
            break
        #print(line, end="")
        sys.stdout.flush()
        if not line.startswith("<item>"):
            continue
        typ, code, length = start_item(line)
        #print (typ, code, length)

        data = ""
        if (length > 0):
            line2 = fi.readline()
            #print('line2:{}'.format(line2), end="")
            r = start_data(line2)
            if (r == -1):
                continue
            line3 = fi.readline()
            #print('line3:{}'.format(line3), end="")
            data = read_data(line3, length)

        # Everything read
        if (typ == 'core'):
            #logger.debug(code)
            #logger.debug(data)

            if (code == "asal"):
                metadata['songalbum'] = data
                # print(data)
            elif (code == "asar"):
                metadata['songartist'] = data
            #elif (code == "ascm"):
            #    metadata['Comment'] = data
            #elif (code == "asgn"):
            #    metadata['Genre'] = data
            elif (code == "minm"):
                metadata['itemname'] = data
            #elif (code == "ascp"):
            #    metadata['Composer'] = data
            #elif (code == "asdt"):
            #    metadata['File Kind'] = data
            #elif (code == "assn"):
            #    metadata['Sort as'] = data
            #elif (code == "clip"):
            #    metadata['IP'] = data

        if (typ == "ssnc" and code == "prgr"):
            state_changed('play', None)
        if (typ == "ssnc" and code == "pfls"):
            metadata = {}
            # print(json.dumps({}))
            state_changed('pause', None)
            sys.stdout.flush()
        if (typ == "ssnc" and code == "pend"):
            metadata = {}
            # print(json.dumps({}))
            sys.stdout.flush()
        if (typ == "ssnc" and code == "PICT"):
            # print(typ, code, length, len(data))
            if (len(data) == 0):
                # print(json.dumps({"image": ""}))
                pass
            else:
                mime = guessImageMime(data)
                # print(mime)
                if (mime == 'image/png'):
                    temp_file = tempfile.NamedTemporaryFile(prefix="image_",
                                                            suffix=".png",
                                                            delete=False,
                                                            dir=tempdirname)
                elif (mime == 'image/jpeg'):
                    temp_file = tempfile.NamedTemporaryFile(prefix="image_",
                                                            suffix=".jpeg",
                                                            delete=False,
                                                            dir=tempdirname)
                else:
                    temp_file = tempfile.NamedTemporaryFile(prefix="image_",
                                                            suffix=".jpg",
                                                            delete=False,
                                                            dir=tempdirname)

                with temp_file as file:
                    file.write(data)
                    file.close()
                    notify_album_artwork(temp_file.name)
                    # logger.info('Wrote file {}'.format(temp_file.name))
                    if asciimatics_avail:
                        # logger.debug('loading image for ascii art')
                        asciimatics_img = ImageFile(temp_file.name,
                                                    height=22,
                                                    colours=16)
                        # print(asciimatics_img)

            sys.stdout.flush()

        if (typ == "ssnc" and code == "mden"):
            # logger.debug('metadata end')

            # print(json.dumps(metadata))
            state_changed('play', metadata)
            sys.stdout.flush()
            metadata = {}
Ejemplo n.º 14
0
def demo(screen):

    scenes = []
    effects = [
        Print(screen,
              ColourImageFile(screen, "tenor.gif", screen.height - 2,
                              uni=screen.unicode_aware,
                              dither=screen.unicode_aware),
              0,
              stop_frame=200),
        Print(screen,
              FigletText("WASP",
                         font='epic' if screen.width > 80 else 'banner'),
              screen.height // 2 - 3,
              colour=7, bg=7 if screen.unicode_aware else 0),
        Print(screen,
              SpeechBubble("press <Space> to continue "),
              screen.height - 5,
              speed=1, transparent=False)
    ]
    scenes.append(Scene(effects))
    effects = [
        Print(screen, ImageFile("love.gif", screen.height - 2, colours=screen.colours),
              0,
              stop_frame=100),
    ]
    scenes.append(Scene(effects))

    effects = [
        Print(screen, ImageFile("sad_to_happy.gif", screen.height - 2, colours=screen.colours),
              0,
              stop_frame=100),
    ]
    scenes.append(Scene(effects))

    effects = [
        Print(screen, ImageFile("sad.jpg", screen.height - 2, colours=screen.colours),
              0,
              stop_frame=100),
    ]
    scenes.append(Scene(effects))

    effects = [
        Print(screen, ImageFile("neutral.jpg", screen.height - 2, colours=screen.colours),
              0,
              stop_frame=100),
    ]
    scenes.append(Scene(effects))

    effects = [
        Print(screen, ImageFile("smile.jpg", screen.height - 2, colours=screen.colours),
              0,
              stop_frame=100),
    ]
    scenes.append(Scene(effects))

    effects = [
        Print(screen, ImageFile("smiling.jpg", screen.height - 2, colours=screen.colours),
              0,
              stop_frame=100),
    ]
    scenes.append(Scene(effects))

    effects = [
        Print(screen, ImageFile("broken_heart.jpg", screen.height - 2, colours=screen.colours),
              0,
              stop_frame=100),
    ]
    scenes.append(Scene(effects))

    effects = [
        Print(screen, ImageFile("heart.jpg", screen.height - 2, colours=screen.colours),
              0,
              stop_frame=100),
    ]
    scenes.append(Scene(effects))

    effects = [
        Print(screen, ColourImageFile(screen, "poop.jpg", screen.height - 2,
                                      uni=screen.unicode_aware, dither=screen.unicode_aware),
              0,
              stop_frame=100),
        Print(screen,
              SpeechBubble("press <X> to exit "),
              screen.height - 5,
              speed=1, transparent=False)
    ]
    scenes.append(Scene(effects))

    screen.play(scenes, stop_on_resize=True)