python - "Sound of sorting" -
i writing small program in python 2.7.10 pygame. im using multithreading play sounds (with winsound) , still draw things fast. trying replicate similar idea of videos saw on youtube of sorting algorithms. unfortunately runs 10 seconds randomly crashes, sounds keep going pygame window goes not responding , drawing not change. if put print "hi" in code somewhere still printing in console pygame still have gone not responding. cant think of whats wrong may multithreading (im new it!)
from random import randint import pygame,winsound,threading,time pygame.locals import * screen=pygame.display.set_mode([1000,500]) def bubblesort(listname): sorting=true while sorting: listchanged=false in range(len(listname)-1): draw(listname,1000/len(listname),500/11,i) if listname[i] < listname[i+1]: listname[i],listname[i+1]=listname[i+1],listname[i] threading.thread(target=playsound,args=([listname[i]])).start() listchanged=true if not listchanged: sorting=false time.sleep(10) pygame.quit() def playsound(frequency): winsound.beep(frequency*100,100) def draw(listname,width,height,comparing): print "hi" screen.fill([0,0,0]) in range(len(listname)): if == comparing or == comparing+1: pygame.draw.rect(screen,[0,255,0],[width*(len(listname)-i),500-(height*listname[i]),width,500]) else: pygame.draw.rect(screen,[255,255,255],[width*(len(listname)-i),500-(height*listname[i]),width,500]) event in pygame.event.get(): if event.type == quit: pygame.quit() pygame.display.update() list1=[] in range(100): list1.append(randint(1,10)) threading.thread(target=bubblesort,args=([list1])).start()
Comments
Post a Comment