當前位置: 首頁>>代碼示例>>Python>>正文


Python Canvas.blit方法代碼示例

本文整理匯總了Python中caca.canvas.Canvas.blit方法的典型用法代碼示例。如果您正苦於以下問題:Python Canvas.blit方法的具體用法?Python Canvas.blit怎麽用?Python Canvas.blit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在caca.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.blit方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from caca.canvas import Canvas [as 別名]
# 或者: from caca.canvas.Canvas import blit [as 別名]
def main():
    """ Main function. """

    try:
        pig = Canvas(0, 0)
        pig.import_from_memory(STRING, "text")
        cv = Canvas(pig.get_width() * 2, pig.get_height() * 2)
    except CanvasError as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(2)

    cv.blit(0, 0, pig, NullCanvas())
    pig.flip()
    cv.blit(pig.get_width(), 0, pig, NullCanvas())
    pig.flip()
    pig.flop()
    cv.blit(0, pig.get_height(), pig, NullCanvas())
    pig.flop()
    pig.rotate_180()
    cv.blit(pig.get_width(), pig.get_height(), pig, NullCanvas())

    for j in range(0, cv.get_height()):
        for i in range(0, cv.get_width(), 2):
            cv.set_color_ansi(caca.COLOR_LIGHTBLUE + (i + j) % 6,
                              caca.COLOR_DEFAULT)

            a = cv.get_attr(-1, -1)
            cv.put_attr(i, j, a)
            cv.put_attr(i+1, j, a)

    print("%s" % cv.export_to_memory('utf8'))
    cv.rotate_left()
    print("%s" % cv.export_to_memory('utf8'))
開發者ID:Kirkman,項目名稱:libcaca,代碼行數:35,代碼來源:text.py

示例2: test_blit

# 需要導入模塊: from caca.canvas import Canvas [as 別名]
# 或者: from caca.canvas.Canvas import blit [as 別名]
 def test_blit(self):
     """ module canvas: Canvas.blit()
     """
     cv1 = Canvas(10, 1)
     cv2 = Canvas(10, 1)
     cv2.put_str(0, 0, "teststring")
     self.assertEqual(0, cv1.blit(0, 0, cv2))
     self.assertEqual("teststring", cv1.export_to_memory("utf8").strip('\n'))
     self.assertRaises(CanvasError, cv1.blit, 0, 0, "abc")
     self.assertRaises(CanvasError, cv1.blit, "a", 0, cv2)
開發者ID:Kirkman,項目名稱:libcaca,代碼行數:12,代碼來源:canvas.py

示例3: test_blit_mask

# 需要導入模塊: from caca.canvas import Canvas [as 別名]
# 或者: from caca.canvas.Canvas import blit [as 別名]
 def test_blit_mask(self):
     """ module canvas: Canvas.blit() (with mask)
     """
     cv1 = Canvas(10, 1)
     cv2 = Canvas(10, 1)
     mask = Canvas(10, 1)
     badm = Canvas()
     cv2.put_str(0, 0, "teststring")
     mask.put_str(0, 0, "####")
     self.assertEqual(0, cv1.blit(0, 0, cv2, mask))
     self.assertEqual("test      ", cv1.export_to_memory("utf8").strip("\n"))
     self.assertRaises(CanvasError, cv1.blit, 0, 0, cv2, badm)
開發者ID:Kirkman,項目名稱:libcaca,代碼行數:14,代碼來源:canvas.py

示例4: main

# 需要導入模塊: from caca.canvas import Canvas [as 別名]
# 或者: from caca.canvas.Canvas import blit [as 別名]
def main():
    """ Main function. """
    try:
        cv = Canvas(0, 0)
        dp = Display(cv)
    except (CanvasError, DisplayError) as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(2)

    sprite = Canvas(0, 0)
    sprite.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK)
    sprite.import_from_memory(THE_PIG, "text")
    sprite.set_handle(sprite.get_width()//2, sprite.get_height()//2)

    cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
    cv.put_str(0, 0, "Centered sprite")
    cv.blit(cv.get_width()//2, cv.get_height()//2, sprite, NullCanvas())

    dp.refresh()
    dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)

    sys.exit(0)
開發者ID:graingert,項目名稱:libcaca,代碼行數:24,代碼來源:blit.py


注:本文中的caca.canvas.Canvas.blit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。