Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on numpy. #274

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

lgautier
Copy link

@lgautier lgautier commented Jan 9, 2022

Make gradients between 4 and 5 times faster while at it.

This is a proposed partial fix for issue #270. Current version of ptext used still requires numpy.

Make gradients between 4 and 5 times faster while at it.
@lordmauve
Copy link
Owner

I'm surprised that smoothscale is faster; each pixel will be blended between 4 values rather than just copied. So if this is faster then it should be possible to go faster still...

@lgautier
Copy link
Author

lgautier commented Jan 9, 2022

The (code to run the) benchmark is in a comment for issue #270. Beside numpy not being as fast as one would expect, possible reasons for increased performance are:

  • the averaging is something the implementation in the backend could delegate to hardware (the chain is pygame zero -> pygame -> SDL).
  • gradient created in-place (no need to allocate an array as large as the screen)

An alternative I have considered is to create a first column of pixels (one pixel per row) and scale across the width. That approach would be better if considering stripes in gradients that are several pixels tall. With a bit of attention this could also help make partial gradients (e.g., sunset or sunrise skies, transition between a planet's atmosphere and space). However, for this to be most useful there would be the need to change the API in pygame zero. Since using scalesmooth was already so much faster that the current implementation, and achieved my goal of removing a strict dependency on numpy. I did not bother experimenting much further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants