I am working on a paint project and it's almost complete but I want it to behave like the ms paint , in which whenever we draw an object (rectangle ,line) it shows it on the screen while we are moving our mouse . I implemented it for only one object i.e the window shows which object I am drawing but when I start drawing another object it wipes the previously drawn one
import pygame
pygame.init()
run = True
screen = pygame.display.set_mode((400,400))
clock = pygame.time.Clock()
screen.fill((255,255,255))
down = None
while run == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
elif event.type == pygame.MOUSEMOTION:
motion = event.pos
screen.fill((255,255,255))
if down:
pygame.draw.line(screen,(0,0,0),(down[0],down[1]),\
(motion[0],motion[1]))
elif event.type == pygame.MOUSEBUTTONDOWN:
down = event.pos
elif event.type == pygame.MOUSEBUTTONUP:
up = event.pos
pygame.draw.line(screen,(0,0,0),(down[0],down[1]),(up[0],up[1]))
down = None
pygame.display.update()
clock.tick(60)
I tried saving the data of the all previously draw objects in an array and then calling a function make(self,arr) to draw it again on the screen but it's very slow. How can I draw the objects like i showed in my program and still have other objects stay on the screen ?