Checking surrounding pixels inefficiently in pygame [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












This checks surrounding pixels to my object's pixel:



self.surr = [None, None, None, None, None, None, None, None]

for i in range(9):
#for x in range(-1, 2):
#for y in range(-1, 2):
if i != 5:
x = i % 3 - 2
y = int((i % 3) / 3) - 1

if x == 0 and y == 0:
pass
else:
PAI = allPixels[(self.x + x) % width][(self.y + y) % height] if allPixels[(self.x + x) % width][(self.y + y) % height] != None else None

self.surr[(y * 3) + x] = (PAI)

return self.surr


This returns a list of length 8 that holds either a Pixel object or None. allPixels is a 2D array that also holds either a Pixel object or None.
I've tried then nested loops that are commented out but they run just a bit slower that the method I'm currently using. This however, is still too slow as if there are 3000 pixels on the screen, which is the lower bounds of the total pixels there will be on the screen in the end, do the maths and you have a LOT going on every frame.



Any help somehow making this run faster/more efficiently would be much appreciated.



If you want to see the whole code, it can be found here.







share|improve this question













closed as off-topic by Gareth Rees, Billal BEGUERADJ, Stephen Rauch, t3chb0t, Toby Speight May 28 at 10:40


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Gareth Rees, Billal BEGUERADJ, Stephen Rauch, t3chb0t
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    I assume allPi is a typo and is meant to be allPixels. Please edit.
    – vnp
    May 20 at 17:59










  • @vnp Yes, it was a typo, I've edited it now
    – Thomas Ayling
    May 20 at 18:04







  • 2




    Investigate: scipy-lectures.org/advanced/image_processing
    – Stephen Rauch
    May 20 at 22:06










  • @StephenRauch Will do, thanks
    – Thomas Ayling
    May 21 at 8:27
















up vote
2
down vote

favorite












This checks surrounding pixels to my object's pixel:



self.surr = [None, None, None, None, None, None, None, None]

for i in range(9):
#for x in range(-1, 2):
#for y in range(-1, 2):
if i != 5:
x = i % 3 - 2
y = int((i % 3) / 3) - 1

if x == 0 and y == 0:
pass
else:
PAI = allPixels[(self.x + x) % width][(self.y + y) % height] if allPixels[(self.x + x) % width][(self.y + y) % height] != None else None

self.surr[(y * 3) + x] = (PAI)

return self.surr


This returns a list of length 8 that holds either a Pixel object or None. allPixels is a 2D array that also holds either a Pixel object or None.
I've tried then nested loops that are commented out but they run just a bit slower that the method I'm currently using. This however, is still too slow as if there are 3000 pixels on the screen, which is the lower bounds of the total pixels there will be on the screen in the end, do the maths and you have a LOT going on every frame.



Any help somehow making this run faster/more efficiently would be much appreciated.



If you want to see the whole code, it can be found here.







share|improve this question













closed as off-topic by Gareth Rees, Billal BEGUERADJ, Stephen Rauch, t3chb0t, Toby Speight May 28 at 10:40


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Gareth Rees, Billal BEGUERADJ, Stephen Rauch, t3chb0t
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    I assume allPi is a typo and is meant to be allPixels. Please edit.
    – vnp
    May 20 at 17:59










  • @vnp Yes, it was a typo, I've edited it now
    – Thomas Ayling
    May 20 at 18:04







  • 2




    Investigate: scipy-lectures.org/advanced/image_processing
    – Stephen Rauch
    May 20 at 22:06










  • @StephenRauch Will do, thanks
    – Thomas Ayling
    May 21 at 8:27












up vote
2
down vote

favorite









up vote
2
down vote

favorite











This checks surrounding pixels to my object's pixel:



self.surr = [None, None, None, None, None, None, None, None]

for i in range(9):
#for x in range(-1, 2):
#for y in range(-1, 2):
if i != 5:
x = i % 3 - 2
y = int((i % 3) / 3) - 1

if x == 0 and y == 0:
pass
else:
PAI = allPixels[(self.x + x) % width][(self.y + y) % height] if allPixels[(self.x + x) % width][(self.y + y) % height] != None else None

self.surr[(y * 3) + x] = (PAI)

return self.surr


This returns a list of length 8 that holds either a Pixel object or None. allPixels is a 2D array that also holds either a Pixel object or None.
I've tried then nested loops that are commented out but they run just a bit slower that the method I'm currently using. This however, is still too slow as if there are 3000 pixels on the screen, which is the lower bounds of the total pixels there will be on the screen in the end, do the maths and you have a LOT going on every frame.



Any help somehow making this run faster/more efficiently would be much appreciated.



If you want to see the whole code, it can be found here.







share|improve this question













This checks surrounding pixels to my object's pixel:



self.surr = [None, None, None, None, None, None, None, None]

for i in range(9):
#for x in range(-1, 2):
#for y in range(-1, 2):
if i != 5:
x = i % 3 - 2
y = int((i % 3) / 3) - 1

if x == 0 and y == 0:
pass
else:
PAI = allPixels[(self.x + x) % width][(self.y + y) % height] if allPixels[(self.x + x) % width][(self.y + y) % height] != None else None

self.surr[(y * 3) + x] = (PAI)

return self.surr


This returns a list of length 8 that holds either a Pixel object or None. allPixels is a 2D array that also holds either a Pixel object or None.
I've tried then nested loops that are commented out but they run just a bit slower that the method I'm currently using. This however, is still too slow as if there are 3000 pixels on the screen, which is the lower bounds of the total pixels there will be on the screen in the end, do the maths and you have a LOT going on every frame.



Any help somehow making this run faster/more efficiently would be much appreciated.



If you want to see the whole code, it can be found here.









share|improve this question












share|improve this question




share|improve this question








edited May 20 at 18:03
























asked May 20 at 16:56









Thomas Ayling

194




194




closed as off-topic by Gareth Rees, Billal BEGUERADJ, Stephen Rauch, t3chb0t, Toby Speight May 28 at 10:40


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Gareth Rees, Billal BEGUERADJ, Stephen Rauch, t3chb0t
If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Gareth Rees, Billal BEGUERADJ, Stephen Rauch, t3chb0t, Toby Speight May 28 at 10:40


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Gareth Rees, Billal BEGUERADJ, Stephen Rauch, t3chb0t
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 2




    I assume allPi is a typo and is meant to be allPixels. Please edit.
    – vnp
    May 20 at 17:59










  • @vnp Yes, it was a typo, I've edited it now
    – Thomas Ayling
    May 20 at 18:04







  • 2




    Investigate: scipy-lectures.org/advanced/image_processing
    – Stephen Rauch
    May 20 at 22:06










  • @StephenRauch Will do, thanks
    – Thomas Ayling
    May 21 at 8:27












  • 2




    I assume allPi is a typo and is meant to be allPixels. Please edit.
    – vnp
    May 20 at 17:59










  • @vnp Yes, it was a typo, I've edited it now
    – Thomas Ayling
    May 20 at 18:04







  • 2




    Investigate: scipy-lectures.org/advanced/image_processing
    – Stephen Rauch
    May 20 at 22:06










  • @StephenRauch Will do, thanks
    – Thomas Ayling
    May 21 at 8:27







2




2




I assume allPi is a typo and is meant to be allPixels. Please edit.
– vnp
May 20 at 17:59




I assume allPi is a typo and is meant to be allPixels. Please edit.
– vnp
May 20 at 17:59












@vnp Yes, it was a typo, I've edited it now
– Thomas Ayling
May 20 at 18:04





@vnp Yes, it was a typo, I've edited it now
– Thomas Ayling
May 20 at 18:04





2




2




Investigate: scipy-lectures.org/advanced/image_processing
– Stephen Rauch
May 20 at 22:06




Investigate: scipy-lectures.org/advanced/image_processing
– Stephen Rauch
May 20 at 22:06












@StephenRauch Will do, thanks
– Thomas Ayling
May 21 at 8:27




@StephenRauch Will do, thanks
– Thomas Ayling
May 21 at 8:27















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation