Guest User

Untitled

a guest
Feb 22nd, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. import pygame
  2.  
  3. def draw_outlined_circle2(surf, color, origin, radius, thickness):
  4. width = radius * 2 + thickness * 2
  5. background = (0, 0, 0, 0)
  6. circle = pygame.Surface((width, width)).convert_alpha()
  7. rect = circle.get_rect()
  8. circle.fill(background)
  9. pygame.draw.circle(circle, color, rect.center, radius)
  10. pygame.draw.circle(circle, background, rect.center, radius - thickness)
  11. surf.blit(circle, (origin[0] - (rect.w / 2), origin[1] - (rect.w / 2)))
  12.  
  13. def draw_outlined_circle0(surf, color, origin, radius, thickness):
  14. pygame.draw.circle(surf, color, origin, radius)
  15. pygame.draw.circle(surf, (0, 0, 0, 255), origin, radius - thickness)
  16.  
  17. surf = pygame.Surface((2000,2000))
  18. radius = 508
  19. thickness = 50
  20. draw_with_pygame = True
  21.  
  22.  
  23. pygame.init()
  24. screen = pygame.display.set_mode((1024, 768))
  25. pygame.display.set_caption('space - toggle draw with pygame(red), escape - quit')
  26. pygame.display.flip()
  27.  
  28. pygame.draw.circle(surf, pygame.Color("red"), (500, 500), radius, thickness)
  29.  
  30. screen.blit(surf, (0,0))
  31. pygame.display.flip()
  32. going = True
  33.  
  34. while going:
  35. events = pygame.event.get()
  36. for e in events:
  37. if (e.type == pygame.QUIT or
  38. (e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE)):
  39. going = False
  40. if e.type == pygame.KEYDOWN and e.key == pygame.K_SPACE:
  41. draw_with_pygame = not draw_with_pygame
  42. if draw_with_pygame:
  43. pygame.draw.circle(surf, pygame.Color("red"), (500, 500), radius, thickness)
  44. else:
  45. draw_outlined_circle2(surf, pygame.Color("white"), (750, 750), radius, thickness)
  46. screen.blit(surf, (0,0))
  47. color_name = 'red' if draw_with_pygame else 'white'
  48. msg = 'space - toggle draw with pygame(%s):%s, escape - quit' % (color_name, draw_with_pygame)
  49. pygame.display.set_caption(msg)
  50. pygame.display.flip()
Add Comment
Please, Sign In to add comment