I have recently build a simple image editor in python. There is nothing specific that I am dissatisfied about regarding this code. I am just asking for general criticism to help me improve
import pygame
import random
import time
x = input("Do you want to edit an image?")
if x == "yes":
image_url = input("please enter image url")
image = pygame.image.load(image_url)
i_edit = True
else:
i_edit = False
pygame.init()
red = (255,0,0)
orange = (255,165,0)
yellow = (255,255,0)
green = (0,255,0)
blue = (0,0,215)
indigo = (75,0,130)
violet = (128,0,128)
black = (0, 0, 0)
white = (255,255,255)
gameDisplay = pygame.display.set_mode((900, 900))
clock = pygame.time.Clock()
color = white
crashed = False
buttpressed = 0
rightkeypressed = False
radius = 10
background_colour = (0,0,0)
gameDisplay.fill(background_colour)
if i_edit:
gameDisplay.blit(image, (0, 0))
while not crashed:
if radius < 5:
radius = 5
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
pygame.display.set_caption("Your Pen Size is {0}".format(radius))
if event.type == pygame.KEYDOWN and rightkeypressed is True:
if event.unicode == 'n':
background_colour = black
if event.unicode == 'w':
background_colour = white
if event.unicode == 'r':
background_colour = red
if event.unicode == 'o':
background_colour = orange
if event.unicode == 'y':
background_colour = yellow
if event.unicode == 'g':
background_colour = green
if event.unicode == 'b':
background_colour = blue
if event.unicode == 'i':
background_colour = indigo
if event.unicode == 'p':
background_colour = violet
if event.unicode == 'e':
color = background_colour
gameDisplay.fill(background_colour)
if event.unicode == 'q':
gameDisplay.blit(image, (0, 0))
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 3:
rightkeypressed = True
if event.type == pygame.MOUSEBUTTONUP:
if event.button == 3:
rightkeypressed = False
if event.type == pygame.KEYDOWN:
if event.unicode == 'n':
color = black
if event.unicode == 'w':
color = white
if event.unicode == 'r':
color = red
if event.unicode == 'o':
color = orange
if event.unicode == 'y':
color = yellow
if event.unicode == 'g':
color = green
if event.unicode == 'b':
color = blue
if event.unicode == 'i':
color = indigo
if event.unicode == 'p':
color = violet
if event.unicode == 'e':
color = background_colour
if event.unicode == '=':
radius += 5
if event.unicode == '-':
radius -= 5
if event.type == pygame.MOUSEBUTTONDOWN:
buttpressed += 1
if event.type == pygame.MOUSEMOTION and (buttpressed%2) != 0:
pygame.draw.circle(gameDisplay, color, pygame.mouse.get_pos(), radius)
pygame.display.update()
clock.tick(60)