I am currently in a challenge with my buddy to see who can code a simple paint program in the least lines. The only requirement, is that the program must include an eraser. How can I possibly shorten this code, while still using proper, beautiful syntax?
import sys, pygame
from pygame.locals import *
pygame.init() #Starts pygame
screen = pygame.display.set_mode((1000,720)) #window, and sets the size
screen.fill((255,255,255)) # Fills background color
brush = pygame.image.load("brush.jpg") #Loads the image into a variable
eraser = pygame.image.load("white.png") #Loads the image into a variable
brush = pygame.transform.scale(brush, (10,10)) #Scales the image into a more useable
eraser = pygame.transform.scale(eraser, (100,100)) #Scales the image into a more
clock = pygame.time.Clock() #Makes a clock to track the ticks within the game
z = 0
while True:
clock.tick(60) #Limits the ticks to 60 (FPS)
x,y = pygame.mouse.get_pos() #Sets two variables for the mouse position
for event in pygame.event.get(): #Recieves events
if event.type == QUIT: #Checks if the event is a QUIT event
pygame.quit() ##Quits##
sys.exit() ##Quits##
elif event.type == MOUSEBUTTONDOWN:
z = 1 #If you press the mouse button down, it sets the screen blit to true
elif event.type == MOUSEBUTTONUP:
z = z - 1 #Does the opposite of the above elif statement
if z == 1: #Cheks if the variable z is true, if it is; updates the screen with the brush
screen.blit(brush,(x-5,y-5))
if event.type == KEYDOWN:
screen.blit(eraser,(x-5,y-5))
pygame.display.update()
4. Do I want the code to be good code, (i.e. not code-golfing, obfuscation, or similar)
in the help center pages \$\endgroup\$