26 ธันวาคม 2558

Published ธันวาคม 26, 2558 by with 0 comment

สร้าง ASCII อนิเมชั่นด้วยภาษาไพทอน

สวัสดีผู้อ่านทุกท่านครับ บทความนี้ผมจะพาผู้อ่านไปลองเล่นสนุก ๆ กับคอมมานด์ไลน์ ด้วยการสร้าง ASCII อนิเมชั่นด้วยภาษาไพทอนกันครับ


ASCII อนิเมชั่น (ASCII animations) ถือกำเนิดขึ้นในยุค 80s โดยนำ ASCII Art มาทำเป็นอนิเมชั่น (อ่านเพิ่มเติมได้ที่ http://www.incredibleart.org/links/ascii.html)

ในภาษาไพทอนมีโมดูลที่สามารถสร้าง ASCII อนิเมชั่นได้ คือ โมดูล Asciimatics

โมดูล Asciimatics เป็นโมดูลช่วยสร้าง ASCII อนิเมชั่น (ASCII animations) แบบเต็มหน้าต่างในบาง platform

  • รองรับการทำงานทั้งใน CentOS 6 & 7, Raspbian (เช่น Debian wheezy), Windows 7, 8 & 10 และ OSX 10.11 และ platform อื่น ๆ
  • ใช้ Apache Software Foundation License 2.0
  • รองรับทั้ง Python 2 และ Python 3

สามารถติดตั้งได้โดยใช้คำสั่ง pip :
pip install asciimatics

โค้ดตัวอย่าง

from asciimatics.effects import Cycle, Stars
from asciimatics.renderers import FigletText
from asciimatics.scene import Scene
from asciimatics.screen import Screen

def demo(screen):
    effects = [
            Cycle(screen,
                  FigletText("ASCIIMATICS", font='big'),
                  int(screen.height / 2 - 8)),
            Cycle(screen,
                  FigletText("ROCKS!", font='big'),
                  int(screen.height / 2 + 3)),
                  Stars(screen, 200)
            ]
    screen.play([Scene(effects, 500)])


Screen.wrapper(demo)

ผลลัพธ์


HAPPY NEW YEAR
โค้ด

ผลลัพธ์
สร้าง ASCII อนิเมชั่นด้วยภาษาไพทอน

อ่านเอกสารการใช้งานได้ที่ https://asciimatics.readthedocs.org/
ติดตามบทความต่อไปนะครับ
ขอบคุณครับ

0 ความคิดเห็น:

แสดงความคิดเห็น

แสดงความคิดเห็นได้ครับ :)