做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

pygame學習筆記(2):畫點的三種方法和動畫實例

來源:懂視網 責編:小采 時間:2020-11-27 14:39:42
文檔

pygame學習筆記(2):畫點的三種方法和動畫實例

pygame學習筆記(2):畫點的三種方法和動畫實例:1、單個像素(畫點) 利用pygame畫點主要有三種方法: 方法一:畫長寬為1個像素的正方形 代碼如下: import pygame,sys pygame.init() screen=pygame.display.set_caption('hello world!') screen=pygame.display.se
推薦度:
導讀pygame學習筆記(2):畫點的三種方法和動畫實例:1、單個像素(畫點) 利用pygame畫點主要有三種方法: 方法一:畫長寬為1個像素的正方形 代碼如下: import pygame,sys pygame.init() screen=pygame.display.set_caption('hello world!') screen=pygame.display.se
1、單個像素(畫點)

利用pygame畫點主要有三種方法:
方法一:畫長寬為1個像素的正方形

代碼如下:


import pygame,sys
pygame.init()
screen=pygame.display.set_caption('hello world!')
screen=pygame.display.set_mode([640,480])
screen.fill([255,255,255])
pygame.draw.rect(screen,[0,0,0],[150,50,1,1],1) #畫1*1的矩形,線寬為1,這里不能是0,因為1*1無空白區域。
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()

方法二:畫個直徑為1的圓

代碼如下:


import pygame,sys
pygame.init()
screen=pygame.display.set_caption('hello world!')
screen=pygame.display.set_mode([640,480])
screen.fill([255,255,255])
pygame.draw.circle(screen,[0,0,0],[150,200],1,1)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()


方法三:這種方法并不是畫上去的,而是改變了surface上某個點的顏色,這樣看上去像是畫了一個點screen.set_at()。另外,如果要得到某個像素的顏色,可以使用screen.get_at()。

代碼如下:


import pygame,sys
pygame.init()
screen=pygame.display.set_caption('hello world!')
screen=pygame.display.set_mode([640,480])
screen.fill([255,255,255])
screen.set_at([150,150],[255,0,0])#將150,150改為紅色。
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()

2、連接多個點形成線

pygame.draw.lines()方法可以將多個點連接成為線。該方法有5個參數:surface表面、顏色、閉合線或者非閉合線(如果閉合為True,否則為False),點的列表,線寬。pygame.draw.lines(surface,[color],False/True,plotpoints,1)。下面的例子畫出了一條馬路,具體如下:

代碼如下:


import pygame,sys
def lineleft(): #畫馬路左邊界
plotpoints=[]
for x in range(0,640):
y=-5*x+1000
plotpoints.append([x,y])
pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
pygame.display.flip()
def lineright():#畫馬路右邊界
plotpoints=[]
for x in range(0,640):
y=5*x-2000
plotpoints.append([x,y])
pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
pygame.display.flip()
def linemiddle():#畫馬路中間虛線
plotpoints=[]
x=300
for y in range(0,480,20):
plotpoints.append([x,y])
if len(plotpoints)==2:
pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
plotpoints=[]
pygame.display.flip()

pygame.init()
screen=pygame.display.set_caption('hello world!')
screen=pygame.display.set_mode([640,480])
screen.fill([255,255,255])
lineleft()
lineright()
linemiddle()
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()

3、引用圖像
在pygame中引用圖像最簡單的以夷伐夷是image函數。下面在馬路的實例中,加入一輛汽車。首先pygame.image.load()函數從硬盤加載一個圖像,并創建一個名為my_car的對象。這里,my_car是一個surface,不過是存在內存中,并未顯示出來,然后用blit(塊移)方法將my_car復制到screen表面上,從而顯示出來。具體代碼如下:

代碼如下:


import pygame,sys
def lineleft():
plotpoints=[]
for x in range(0,640):
y=-5*x+1000
plotpoints.append([x,y])
pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
pygame.display.flip()
def lineright():
plotpoints=[]
for x in range(0,640):
y=5*x-2000
plotpoints.append([x,y])
pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
pygame.display.flip()
def linemiddle():
plotpoints=[]
x=300
for y in range(0,480,20):
plotpoints.append([x,y])
if len(plotpoints)==2:
pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
plotpoints=[]
pygame.display.flip()
def loadcar(): #載入car圖像
my_car=pygame.image.load('ok1.jpg') #當前文件夾下的ok1.jpg文件
screen.blit(my_car,[320,320])
pygame.display.flip()

pygame.init()
screen=pygame.display.set_caption('hello world!')
screen=pygame.display.set_mode([640,480])
screen.fill([255,255,255])
lineleft()
lineright()
linemiddle()
loadcar()
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()

素材:ok1.jpg

4、動畫

計算機動畫實際上就是把圖像從一個地方移動到另一個地方,同時幾個連接動作交待顯示就會產生逼真的效果。因此,在做動畫中,最基本要考慮的因素主要是三個,一是時間,什么時間移動,多長時間變下一個動作,二是位置,從什么位置到什么位置,三是動作,前后兩個動作的連續性。在這個例子中,因為車是俯視的,所以車輪轉動實際是看不到的,所以不用考慮連續動作的變化,而是只考慮車的位置和多長時間移動即可。第一步pygame.time.delay()來實現時間延遲;第二步利用pygame.draw.rect()把原來位置的圖像覆蓋掉;第三步screen.blit()在新位置引入圖像。下面的例子實現了汽車從駛入到駛出的過程。

代碼如下:


import pygame,sys
def lineleft():
plotpoints=[]
for x in range(0,640):
y=-5*x+1000
plotpoints.append([x,y])
pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
pygame.display.flip()
def lineright():
plotpoints=[]
for x in range(0,640):
y=5*x-2000
plotpoints.append([x,y])
pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
pygame.display.flip()
def linemiddle():
plotpoints=[]
x=300
for y in range(0,480,20):
plotpoints.append([x,y])
if len(plotpoints)==2:
pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
plotpoints=[]
pygame.display.flip()
def loadcar(yloc):
my_car=pygame.image.load('ok1.jpg')
locationxy=[310,yloc]
screen.blit(my_car,locationxy)
pygame.display.flip()


if __name__=='__main__':
pygame.init()
screen=pygame.display.set_caption('hello world!')
screen=pygame.display.set_mode([640,480])
screen.fill([255,255,255])
lineleft()
lineright()
linemiddle()

while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
for looper in range(480,-140,-50):
pygame.time.delay(200)
pygame.draw.rect(screen,[255,255,255],[310,(looper+132),83,132],0)
loadcar(looper)

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

pygame學習筆記(2):畫點的三種方法和動畫實例

pygame學習筆記(2):畫點的三種方法和動畫實例:1、單個像素(畫點) 利用pygame畫點主要有三種方法: 方法一:畫長寬為1個像素的正方形 代碼如下: import pygame,sys pygame.init() screen=pygame.display.set_caption('hello world!') screen=pygame.display.se
推薦度:
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 孟州市| 蕉岭县| 桦南县| 青冈县| 威远县| 临汾市| 敦煌市| 烟台市| 色达县| 深水埗区| 奉新县| 棋牌| 酉阳| 崇明县| 五大连池市| 蕉岭县| 滕州市| 临沂市| 沅江市| 电白县| 石台县| 尉氏县| 锡林郭勒盟| 克东县| 泰来县| 科尔| 承德县| 金秀| 山东| 江达县| 平山县| 宜城市| 长沙县| 洛宁县| 中江县| 景宁| 龙泉市| 镶黄旗| 财经| 高陵县| 垦利县|