#πŸ”’ pygame being extremely slow

19 messages Β· Page 1 of 1 (latest)

light crown
#

hi, i am trying to wtite a program that takes an image file and then puts it into the pygame screen pixel by pixel, its working very well but it's extremely slow

import pygame
import time
iss = pygame.image.load('myimage.jpg')
pygame.init
sc = pygame.display
w,h = iss.get_width(), iss.get_height()
ds = sc.set_mode((w,h))
ru = True
cl = pygame.time.Clock()
sc.set_caption("hi")
x,y=0,0
for y in range(h):
    for x in range(w):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                y=h
                break
        ds.set_at((x,y), iss.get_at((x,y)))
        x +=1
        print(x,y)
        sc.flip()
    y+=1
time.sleep(50)
pygame.quit()
quartz starBOT
#

@light crown

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

dusky sundial
#

I think doing anything pixel-by-pixel is going to be slow.

#

why do you want it to be one pixel at a time?

little parcel
#

if its an aesthetic loading thing, why not clump it into pixel groups of something like 50x50 pixels or something to speed it up

light crown
little parcel
#

well first, do you want it to be pixel by pixel or just insert the image in in one go?

light crown
#

could you teach me both

little parcel
#

as for clumping the pixels like that, its possible yes, but i dont know how to do it off the top of my head since ive never needed to

light crown
little parcel
#

what if you assigned every pixel then updated the screen?

#

something tells me you might be updating the screen every pixel draw

light crown
little parcel
#

yeah its just going to be slow no matter what you do

#

you might be able to multithread the generation and then just iterate through the list it produces as it makes it to make it slightly faster, but thats still going to be slow

quartz starBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.