|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import pygame |
| 4 | +import pygame.gfxdraw |
| 5 | +from PIL import Image, ImageDraw |
| 6 | + |
| 7 | +# --- constants --- |
| 8 | + |
| 9 | +BLACK = ( 0, 0, 0) |
| 10 | +WHITE = (255, 255, 255) |
| 11 | +BLUE = ( 0, 0, 255) |
| 12 | +GREEN = ( 0, 255, 0) |
| 13 | +RED = (255, 0, 0) |
| 14 | +GREY = (128, 128, 128) |
| 15 | + |
| 16 | +PI = 3.1415 |
| 17 | + |
| 18 | +# --- main ---- |
| 19 | + |
| 20 | +pygame.init() |
| 21 | +screen = pygame.display.set_mode((800,600)) |
| 22 | + |
| 23 | +# - generate PIL image - |
| 24 | + |
| 25 | +pil_size = 300 |
| 26 | + |
| 27 | +pil_image = Image.new("RGBA", (pil_size, pil_size)) |
| 28 | +pil_draw = ImageDraw.Draw(pil_image) |
| 29 | +#pil_draw.arc((0, 0, pil_size-1, pil_size-1), 0, 270, fill=RED) |
| 30 | +pil_draw.pieslice((0, 0, pil_size-1, pil_size-1), 330, 0, fill=GREY) |
| 31 | + |
| 32 | +# - convert to PyGame image - |
| 33 | + |
| 34 | +mode = pil_image.mode |
| 35 | +size = pil_image.size |
| 36 | +data = pil_image.tobytes() |
| 37 | + |
| 38 | +image = pygame.image.fromstring(data, size, mode) |
| 39 | +image_rect = image.get_rect(center=screen.get_rect().center) |
| 40 | + |
| 41 | +# - mainloop - |
| 42 | + |
| 43 | +clock = pygame.time.Clock() |
| 44 | +running = True |
| 45 | + |
| 46 | +while running: |
| 47 | + |
| 48 | + clock.tick(10) |
| 49 | + |
| 50 | + for event in pygame.event.get(): |
| 51 | + if event.type == pygame.QUIT: |
| 52 | + running = False |
| 53 | + if event.type == pygame.KEYDOWN: |
| 54 | + if event.key == pygame.K_ESCAPE: |
| 55 | + running = False |
| 56 | + |
| 57 | + screen.fill(RED) |
| 58 | + #pygame.draw.arc(screen, BLACK, (300, 200, 200, 200), 0, PI/2, 1) |
| 59 | + #pygame.gfxdraw.pie(screen, 400, 300, 100, 0, 90, RED) |
| 60 | + #pygame.gfxdraw.arc(screen, 400, 300, 100, 90, 180, GREEN) |
| 61 | + screen.blit(image, image_rect) |
| 62 | + pygame.display.flip() |
| 63 | + |
| 64 | +# - end - |
| 65 | + |
| 66 | +pygame.quit() |
0 commit comments