(Python3)- PyGame 基本參數學習-4 (*矩形、圓形畫圖*)

(Python3)- PyGame 基本參數學習-4 (*矩形、圓形畫圖*)

(Python3)- PyGame 基本參數學習-3 (*矩形、圓形畫圖*)

import pygame,sys
import time
import random

pygame.init() #模塊初始化,任何pygame程序均需要執行此句
screencaption=pygame.display.set_caption('hello world') #定義窗口的標題為'hello world'
screen=pygame.display.set_mode([640,480]) #定義窗口大小為640*480
screen.fill([255,255,255]) #用白色填充窗口
for i in range(10):
    zhijing=random.randint(0,100)
    width=random.randint(0,255)
    height=random.randint(0,100)
    top=random.randint(0,400)
    left=random.randint(0,500)
    pygame.draw.circle(screen,[0,0,0],[top,left],zhijing,1)
    pygame.draw.rect(screen,[255,0,0],[left,top,width,height],3)
#pygame.draw.rect()-用來創建一個矩形。Rect(left,top,width,height)用來定義位置和寬高
#pygame.draw.circle()-(1)畫圓的表面,在本例中用screen創建了一個窗口,所以是畫在screen表面上。(2)用什么顏色來畫,如用紅色[255,0,0]。(3)在什么位置畫,[top,left]。(4)直徑。(5)線寬,其中0表示完成填充
pygame.display.flip()
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            sys.exit()
#pygame有一個事件循環,不斷檢查用戶在做什么。事件循環中,如何讓循環中斷下來(pygame形成的窗口中右邊的插號在未定義前是不起作用的)

 

 

 

免責聲明:

1.本影像檔案皆從網上搜集轉載,不承擔任何技術及版權問題。

2.如有下載連結僅供寬頻測試研究用途,請下載後在24小時內刪除,請勿用於商業。

3.若侵犯了您的合法權益,請來信通知我們,我們會及時刪除,給您帶來的不便,深表歉意。



發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *