LoginSignup
5

More than 5 years have passed since last update.

派手にズンドコきよし with Python

Posted at

派手に!

「キ・ヨ・シ!」を派手にできないかと思っていたらちょうどいいのが
peterbrittain/asciimatics: A cross platform package to do curses-like operations and create ASCII art animations

A cross platform package to do curses-like operations and create ASCII art animations

実装

ズンドコ部分は以下から拝借
Pythonでズンドコキヨシ(ジェネレータ) - Qiita

コード

# -*- coding: utf-8 -*-
from asciimatics.effects import Cycle, Stars
from asciimatics.renderers import ColourImageFile
from asciimatics.scene import Scene
from asciimatics.screen import Screen
from collections import deque
import random
import time

z = u'ズン'
d = u'ドコ'

def kiyoshi(screen):
    effects = [
        Cycle(
            screen,
            ColourImageFile(screen,"kiyoshi.gif",15),
            (screen.height - 15)/ 2)
        ,Stars(screen, 200)
    ]
    screen.play([Scene(effects)], stop_on_resize=True)

def zndkkys2():
    state = 0
    while True:
        num = random.choice((0, 1, ))
        # ズンならカウントアップ
        if num:
            yield z
            state += 1
        else:
            yield d
            # ドコの前に4回以上ズンが連続していたらキ・ヨ・シ!
            if state >= 4:
                return
            # ドコの前のズンが3回以下ならカウントを初期化
            else:
                state = 0

if __name__ == '__main__':
    print ''.join(zndkkys2())
    time.sleep(1)
    Screen.wrapper(kiyoshi)

以下の画像を元にアスキーアートを生成
kiyoshi.gif

kiyoshi2.png
qで停止(プログラム側での止め方がわからない……)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5