1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
import pygame,time,copy,math,random,sys,traceback
def getbox(width,height,transparentPercent,text):
box=pygame.Surface((width,height)
box.set_alpha(128) #transparency from 0 to 255
box.fill((0,0,0)) #fill with black, easy way to make a black border
box.fill((0,255,0), (2,2,width-4,height-4)) #fill inside of border with green
pygame.font.init()
f=pygame.font.Font(None,24)
mytext=f.render(text,True,(0,0,0))
box.blit(mytext,(8,8))
return box
def stripe(surf,c1,c2,stripeheight):
flip=0
for y in range(0,surf.get_height(),stripeheight):
if flip==0:
surf.fill(c1,(0,y,surf.get_width(),stripeheight))
else:
surf.fill(c2,(0,y,surf.get_width(),stripeheight))
flip=(flip+1)%2
sw=512
sh=512
screen=pygame.display.set_mode((sw,sh))
box=getbox(256,128,128,"hello")
try:
cc=0
running=True
while running:
for e in pygame.event.get():
if e.type==pygame.QUIT:
running=False
if e.type==pygame.KEYDOWN and e.key==pygame.K_SPACE:
pass
elif e.type==pygame.MOUSEBUTTONDOWN:
pass
#screen.fill((255,0,0))
stripe(screen,(255,0,0),(0,0,255),50)
screen.blit(box,(0,0))
pygame.display.flip()
time.sleep(0.1)
except Exception, e:
tb = sys.exc_info()[2]
traceback.print_exception(e.__class__, e, tb)
pygame.quit()
|