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 53 54 55 56
| import pygame as pg
from pygame import gfxdraw
couleur_transparence = (100, 0, 120)
pg.init()
ecran = pg.display.set_mode((300, 300))
# Surface jaune
surf_origine = pg.Surface((200, 100))
rect_origine = surf_origine.fill((255, 255, 0))
# Triangles
coords_triangles = (
(0, 0, 100, 0, 0, 50,), # hg
(100, 0, 200, 0, 200, 50,), # hd
(0, 100, 100, 100, 0, 50,), # bg
(200, 100, 100, 100, 200, 50,), # bd
)
for coords in coords_triangles :
gfxdraw.filled_trigon(
surf_origine,
*coords,
couleur_transparence
)
# Définition de la couleur de transparebnce lors du blit
surf_origine.set_colorkey(couleur_transparence)
# Surface bleue
surf_dest = pg.Surface((200, 100))
rect_dest = surf_dest.fill((0, 0, 255))
rect_dest.topleft = 50, 50
surf_dest.blit(surf_origine, (0, 0))
ecran.blit(surf_dest, rect_dest)
pg.display.update()
clock = pg.time.Clock()
while True :
events = pg.event.get()
for event in events :
if event.type == pg.QUIT :
break
else :
clock.tick(5)
continue
break
pg.quit() |
Partager