【发布时间】:2015-08-09 10:52:59
【问题描述】:
我正在尝试使用渐变来更改三角形的颜色,同时定期旋转它。这是我的代码。清除表面似乎有问题,因为之前的输出没有被清除,并且渐变流效果仅对第一个三角形可见。
import pygame, sys
import time
import random
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((500, 500), 0, 32)
pygame.display.set_caption('Drawing')
t = 0
i = 0
d = 0
# set up the colors
WHITE = (255,255,255)
GREEN = ((113, 201, 106),(98, 187, 91),(84, 174, 77),(69, 160, 63),(54, 147, 49),(40, 134, 35))
# draw on the surface object
DISPLAYSURF.fill(WHITE)
newSurf = pygame.transform.rotate(DISPLAYSURF, d)
pygame.draw.polygon(newSurf,GREEN[i],((250,70),(400,300),(100,300)))
t = 0.2
while True:
DISPLAYSURF.fill(WHITE)
DISPLAYSURF.blit(newSurf, (0,0,))
pygame.display.update()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if i==5:
f = 0
d = -90
newSurf = pygame.transform.rotate(DISPLAYSURF, d)
time.sleep(0.4)
if i==0:
f = 1
if f==1:
i = i+1
else:
i = i-1
pygame.draw.polygon(newSurf,GREEN[i],((250,70),(400,300),(100,300)))
time.sleep(t)
由于输出是动画,我不能在这里发布。相反,我发布了几个屏幕截图-
【问题讨论】: