Advertisement
koronabora

Untitled

Mar 1st, 2023
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import math
  3. import sys
  4.  
  5. import cairo
  6. import pygame
  7.  
  8. from time import sleep
  9.  
  10.  
  11. def draw(surface):
  12.     x, y, radius = (250, 250, 200)
  13.     ctx = cairo.Context(surface)
  14.     ctx.set_line_width(15)
  15.     ctx.arc(x, y, radius, 0, 2.0 * math.pi)
  16.     ctx.set_source_rgb(0.8, 0.8, 0.8)
  17.     ctx.fill_preserve()
  18.     ctx.set_source_rgb(1, 1, 1)
  19.     ctx.stroke()
  20.  
  21. def clear(surface):
  22.     ctx = cairo.Context(surface)
  23.     ctx.set_source_rgb(0.0, 0.0, 0.0)
  24.     ctx.paint()
  25.  
  26. isPressed = False
  27.  
  28. def input(events):
  29.     global isPressed
  30.     for event in events:
  31.         if event.type == pygame.QUIT:
  32.             sys.exit(0)
  33.         elif event.type == pygame.MOUSEBUTTONDOWN:
  34.             isPressed = True
  35.         elif event.type == pygame.MOUSEBUTTONUP:
  36.             isPressed = False
  37.  
  38.  
  39. def main():
  40.     width, height = 512, 512
  41.     surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
  42.     pygame.init()
  43.     pygame.display.set_mode((width, height))
  44.     screen = pygame.display.get_surface()
  45.  
  46.     while True:
  47.         if isPressed:
  48.             clear(surface)
  49.         else:
  50.             draw(surface)
  51.  
  52.         buf = surface.get_data()
  53.         image = pygame.image.frombuffer(buf, (width, height), "RGBA")
  54.         screen.blit(image, (0, 0))
  55.         pygame.display.flip()
  56.  
  57.         input(pygame.event.get())
  58.  
  59.  
  60. if __name__ == "__main__":
  61.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement