Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import math
- import sys
- import cairo
- import pygame
- from time import sleep
- def draw(surface):
- x, y, radius = (250, 250, 200)
- ctx = cairo.Context(surface)
- ctx.set_line_width(15)
- ctx.arc(x, y, radius, 0, 2.0 * math.pi)
- ctx.set_source_rgb(0.8, 0.8, 0.8)
- ctx.fill_preserve()
- ctx.set_source_rgb(1, 1, 1)
- ctx.stroke()
- def clear(surface):
- ctx = cairo.Context(surface)
- ctx.set_source_rgb(0.0, 0.0, 0.0)
- ctx.paint()
- isPressed = False
- def input(events):
- global isPressed
- for event in events:
- if event.type == pygame.QUIT:
- sys.exit(0)
- elif event.type == pygame.MOUSEBUTTONDOWN:
- isPressed = True
- elif event.type == pygame.MOUSEBUTTONUP:
- isPressed = False
- def main():
- width, height = 512, 512
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
- pygame.init()
- pygame.display.set_mode((width, height))
- screen = pygame.display.get_surface()
- while True:
- if isPressed:
- clear(surface)
- else:
- draw(surface)
- buf = surface.get_data()
- image = pygame.image.frombuffer(buf, (width, height), "RGBA")
- screen.blit(image, (0, 0))
- pygame.display.flip()
- input(pygame.event.get())
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement