python / pygames

DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
I have been playing with pygames to draw points on a surface using the following code.
# First loop for number of ileratitations, screen is refreshed once each loop.for x in range (0,500):
	#rects = [pygame.Rect(0,0,0,0)]
	# Loop to update each star in turn, write the screen pixel back to background, draw new pixel and save the areas for the screen refresh task. 
	for star in StarA:

		star[6] = (star[0]*cosT[star[4]]) + star[2]
		star[7] = (star[1]*sinT[star[4]]) + star[3]
		star[4] = star[4] + star[5]
		if star[4] >= 359:
			star[4] = 0
		windowSurface.set_at((int(star[6]), int(star[7])), WHITE)

as you can see I tried both full screen updates and just updating the changed pixels. however they real performance hit in the graphic is not the screen update. but the drawing of each star/pixel (there are 200 stars in StarA) this is where the time is taken when i profile the script.

So can any one suggest a better method to draw this to screen? I don't need to use pygames as the only reason I have done so it the nice simple interface. but I am more concerned with performance as this is running on a raspberry pi, and I would like to get it running with 1000+ stars at 25+FPS. Now I know i can pre calculate all the data points if needed, so it outputting to screen that I need to work on. The pi does have a GPU, but no idea how to make best use of it. I feel at the moment I am doing it in the most basic way and could get it to work a lot better.

  • If you can't explain it simply, you don't understand it well enough. Albert Einstein
  • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
Sign In or Register to comment.