Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- # === CONSTANTS ===
- BLACK = ( 0, 0, 0)
- WHITE = (255, 255, 255)
- PIXEL_SIZE = 10
- # === CLASSES ===
- # empty
- # === FUNCTIONS ===
- # empty
- # === DATA ===
- colors = {
- '#': BLACK,
- ' ': WHITE,
- }
- data = [
- " ######## ######## ",
- " ## # # # # ## ",
- "# # # # # # # #",
- "# # # # # # # #",
- " ## ##### ## ",
- " # ##### # ",
- " # # # # ",
- " # # # # ",
- " # # # # ",
- " # # # # ",
- " # # # # ",
- " # # # # ",
- " ######## ######## ",
- ]
- # === MAIN ===
- # --- init ---
- pygame.init()
- screen = pygame.display.set_mode([400,400])
- pygame.display.set_caption('okulary')
- # --- draws ---
- screen.fill(WHITE)
- # create only once
- rect = pygame.Rect(0, 0, PIXEL_SIZE, PIXEL_SIZE)
- for y, row in enumerate(data):
- for x, char in enumerate(row):
- rect.x = x*PIXEL_SIZE
- rect.y = y*PIXEL_SIZE
- screen.fill(colors[char], rect=rect)
- pygame.display.update()
- # --- mainloop ---
- running = True
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- elif event.type == pygame.MOUSEBUTTONDOWN:
- if event.button == 1: # left button
- # Python 2: rounding to integer using /
- # Python 3: rounding to integer using //
- col = event.pos[0] // PIXEL_SIZE
- row = event.pos[1] // PIXEL_SIZE
- # first pixel
- rect.x = col*PIXEL_SIZE
- rect.y = row*PIXEL_SIZE
- screen.fill(BLACK, rect=rect) # BLACK
- # pixel on the left
- rect.x -= PIXEL_SIZE
- screen.fill(BLACK, rect=rect) # BLACK
- # send on monitor
- pygame.display.update()
- elif event.button == 3: # right button
- # Python 2: rounding to integer using /
- # Python 3: rounding to integer using //
- col = event.pos[0] // PIXEL_SIZE
- row = event.pos[1] // PIXEL_SIZE
- # first pixel
- rect.x = col*PIXEL_SIZE
- rect.y = row*PIXEL_SIZE
- screen.fill(WHITE, rect=rect) # WHITE
- # pixel on the left
- rect.x -= PIXEL_SIZE
- screen.fill(WHITE, rect=rect) # WHITE
- # send on monitor
- pygame.display.update()
- # --- the end ---
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement