Pygame圖形
Pygame的座標原點(0,0)點位於左上角,X軸自左向右,Y軸自上向下,單位爲像素。
pygame.draw.line(Surface, color, start_pos, end_pos, width)此方法用於繪製一條線段。
pygame.draw.rect(Surface, color, Rect)此方法用於繪製一個矩形
pygame.draw.rect(Surface, color, Rect, width)此方法用於繪製一個矩形框
import pygame
import sys
#from pygame.locals import *
pygame.init() # 初始化pygame,爲使用硬件做準備
pygame.display.set_caption("Drawing") # 設置窗口標題
screen=pygame.display.set_mode((400,300))
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = ( 0, 255, 0)
BLUE = ( 0, 0, 255)
screen.fill(WHITE)
# 繪製一條線
pygame.draw.line(screen, GREEN, [0, 0], [150,30], 10)
# 繪製一個矩形
pygame.draw.rect(screen, BLACK, [150, 10, 100, 100],15)
while True: # 遊戲主循環
for event in pygame.event.get():
if event.type == pygame.QUIT: # 接收到退出時間後退出程序
pygame.quit()
sys.exit()
pygame.display.update()