python - Why does this pygame program freeze? -
below program using pygame
updates histogram values change.
however after few seconds of running, program freezes. can point out error?
import random import pygame screen_size = screen_width, screen_height = 800, 600 frame_rate = 50 background_color = pygame.color("white") bar_color = pygame.color("black") bucket_cnt = 20 pygame.init() screen = pygame.display.set_mode(screen_size) screen.fill(background_color) buckets = bucket_cnt*[0] bar_w = screen_width / bucket_cnt clock = pygame.time.clock() background = pygame.surface(screen.get_size()) background.fill(background_color) while true: clock.tick(frame_rate) random.seed() idx = random.randrange(bucket_cnt) buckets[idx] += 1 # create rectangles representing bars in histogram. bars = [pygame.rect(i*bar_w, screen_height - buckets[i], bar_w, buckets[i]) in range(bucket_cnt)] # draw bars on background [pygame.draw.rect(background, bar_color, b, 5) b in bars] # blit background screen.blit(background, (0, 0)) # show "stuff" on screen pygame.display.flip()
edit
these suggestions. i've changed code using follow them, code still freezes. here how code looks now:
import random import pygame screen_size = screen_width, screen_height = 800, 600 frame_rate = 50 background_color = pygame.color("white") bar_color = pygame.color("black") bucket_cnt = 20 growth_rate = 10 pygame.init() screen = pygame.display.set_mode(screen_size) screen.fill(background_color) buckets = bucket_cnt*[0] bar_w = screen_width / bucket_cnt clock = pygame.time.clock() background = pygame.surface(screen.get_size()) background.fill(background_color) # create rectangles representing bars in histogram. bars = [pygame.rect(i*bar_w, screen_height - buckets[i], bar_w, buckets[i]) in range(bucket_cnt)] random.seed() while true: clock.tick(frame_rate) idx = random.randrange(bucket_cnt) buckets[idx] += 1 bars[idx].inflate_ip(0, growth_rate) # draw bars on background pygame.draw.rect(background, bar_color, bars[idx]) # blit background screen.blit(background, (0, 0)) # show "stuff" on screen pygame.display.flip()
i want apologize taking everybody's time. turns out there no issue code. work machine overloaded various processes. running multi-threaded test , virtual machine (which compiling large code base). explains why program freezing. thank djmcmayhem trying out code. special shout out alex van leiw. learned few new things pygame today.
Comments
Post a Comment