欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于Python利用Pygame實現(xiàn)翻轉(zhuǎn)圖像

 更新時間:2022年02月16日 14:31:17   作者:聆聽世界的魚  
這篇文章主要介紹了基于Python利用Pygame實現(xiàn)翻轉(zhuǎn)圖像,我們將了解如何使用Pygame翻轉(zhuǎn)圖像,要翻轉(zhuǎn)圖像,我們需要使用pygame.transform.flip(Surface,?xbool,?ybool)?方法,該方法被調(diào)用來根據(jù)我們的需要在垂直方向或水平方向翻轉(zhuǎn)圖像,下面來看看具體的實現(xiàn)過程吧

前言:

要翻轉(zhuǎn)圖像,我們需要使用pygame.transform.flip(Surface, xbool, ybool) 方法,該方法被調(diào)用來根據(jù)我們的需要在垂直方向或水平方向翻轉(zhuǎn)圖像。

語法:

pygame.transform.flip(Surface, xbool, ybool)

原始圖像如下:

1、垂直翻轉(zhuǎn)圖像

我們在垂直方向上翻轉(zhuǎn)圖像。我們將使用 pygame.transform.flip() 來垂直顯示圖像。將 xbool 作為 True 和 ybool 作為 False 傳遞,這樣圖像就會垂直翻轉(zhuǎn)。

代碼如下:

# 導入 pygame 和 sys
import pygame
import sys


from pygame.locals import *


# 初始化pygame
# 導入模塊
pygame.init()
pygame.display.set_caption('www.linuxmi.com')


# 圖像大小將顯示在屏幕上
screen = pygame.display.set_mode((1300, 600), 0, 32)


# pygame.image.load() 將返回
# 有圖像的對象
img = pygame.image.load('linuxmi.com.png')


while True:


? ? # 背景顏色
? ? screen.fill((255, 255, 255))


? ? # 復制圖像
? ? img_copy = img.copy()


? ? # pygame.transform.flip() 將翻轉(zhuǎn)圖像
? ? img_with_flip = pygnsformame.tra.flip(img_copy, False, True)


? ? # surface.blit() 函數(shù)繪制一個源
? ? # 在這個表面上
? ? screen.blit(img_with_flip, (50 + 1 * 120, 100))


? ? # 退出屏幕的事件偵聽器
? ? for event in pygame.event.get():
? ? ? ? if event.type == QUIT:
? ? ? ? ? ? pygame.quit()
? ? ? ? ? ? sys.exit()


? ? # 每秒更新幀數(shù)
? ? pygame.display.update()

效果圖如下:

2、水平方向翻轉(zhuǎn)圖像

我們在水平方向翻轉(zhuǎn)圖像。對于這個 xbool 作為 False 和 ybool 作為 True 傳遞,水平翻轉(zhuǎn)它。

代碼如下:

# 導入 pygame 和 sys
import pygame
import sys


from pygame.locals import *


# 初始化pygame
# 導入模塊
pygame.init()
pygame.display.set_caption('www.linuxmi.com')


# 圖像大小將顯示在屏幕上
screen = pygame.display.set_mode((1300, 600), 0, 32)


# pygame.image.load() 將返回
# 有圖像的對象
img = pygame.image.load('linuxmi.com.png')


while True:


? ? # 背景顏色
? ? screen.fill((255, 255, 255))


? ? # 復制圖像
? ? img_copy = img.copy()


? ? # pygame.transform.flip() 將翻轉(zhuǎn)圖像
? ? img_with_flip = pygame.transform.flip(img_copy, False, True)


? ? # surface.blit() 函數(shù)繪制一個源
? ? # 在這個表面上
? ? screen.blit(img_with_flip, (50 + 1 * 120, 100))


? ? # 退出屏幕的事件偵聽器
? ? for event in pygame.event.get():
? ? ? ? if event.type == QUIT:
? ? ? ? ? ? pygame.quit()
? ? ? ? ? ? sys.exit()


? ? # 每秒更新幀數(shù)
? ? pygame.display.update()

顯示如下:

到此這篇關(guān)于 基于Python利用Pygame實現(xiàn)翻轉(zhuǎn)圖像的文章就介紹到這了,更多相關(guān)Pygame實現(xiàn)翻轉(zhuǎn)圖像內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論