# import math g.norefresh() particle = [[0,0,0,0,0,0,0,0,0,10], [0,0,0,0,0,0,0,0,0,20], [0,0,0,0,0,0,0,0,0,30], [0,0,0,0,0,0,0,0,0,60], [0,0,0,0,0,0,0,0,0,70], [0,0,0,0,0,0,0,0,0,30], [0,0,0,0,0,0,0,0,0,40], [0,0,0,0,0,0,0,0,0,50], [0,0,0,0,0,0,0,0,0,60], [0,0,0,0,0,0,0,0,0,70], [0,0,0,0,0,0,0,0,0,80], [0,0,0,0,0,0,0,0,0,90], [0,0,0,0,0,0,0,0,0,80], [0,0,0,0,0,0,0,0,0,70], [0,0,0,0,0,0,0,0,0,50], [0,0,0,0,0,0,0,0,0,50], [0,0,0,0,0,0,0,0,0,30], [0,0,0,0,0,0,0,0,0,20], [0,0,0,0,0,0,0,0,0,10], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,20], [0,0,0,0,0,0,0,0,0,130], [0,0,0,0,0,0,0,0,0,104], [0,0,0,0,0,0,0,0,0,105], [0,0,0,0,0,0,0,0,0,140], [0,0,0,0,0,0,0,0,0,100], [0,0,0,0,0,0,0,0,0,190], [0,0,0,0,0,0,0,0,0,180], [0,0,0,0,0,0,0,0,0,170], [0,0,0,0,0,0,0,0,0,60], [0,0,0,0,0,0,0,0,0,40], [0,0,0,0,0,0,0,0,0,20], [0,0,0,0,0,0,0,0,0,50], [0,0,0,0,0,0,0,0,0,40], [0,0,0,0,0,0,0,0,0,30], [0,0,0,0,0,0,0,0,0,0.1], [0,0,0,0,0,0,0,0,0,30], [0,0,0,0,0,0,0,0,0,20], [0,0,0,0,0,0,0,0,0,10], [0,0,0,0,0,0,0,0,0,0]] angles = [5,15,25,35,45,55,65,175,185,40,30,20,100,130,140,50,230,30,230,30] aveloc = [0,0] def paint(x,y,val=0): g.setPixel(x,y,max(val,g.getPixel(x,y)+10)) def drawParticle(i): for j in range(10): x = int(particle[i][j]) y = int(particle[i+20][j]) g.setPixel(x, y, j*10) #paint(x,y) def moveParticle(i): for j in range(1,10): particle[i][j-1] = particle[i][j] particle[i+20][j-1] = particle[i+20][j] particle[i][9] = particle[i][8] + math.cos(angles[i]*2*3.141592653/360) particle[i+20][9] = particle[i+20][8] + math.sin(angles[i]*2*3.141592653/360) def computeAveLoc(): global aveloc sx = 0 sy = 0 for i in range(20): sx = sx + particle[i][-1] sy = sy + particle[i+20][-1] aveloc[0] = sx/20.0 aveloc[1] = sy/20.0 def turnParticle(i): dx = particle[i][-1] - aveloc[0] dy = particle[i+20][-1] - aveloc[1] ang = math.atan(dy/dx) if (dx < 0): ang = (ang + 3.1415926535) % (2 * 3.1415926535) da = ang - angles[i]*2*3.1415926535/360 if (da > 0 and da < 3.14159): angles[i] = angles[i] - i/2 - 1 else: angles[i] = angles[i] + i/2 + 1 #angles[i] = (angles[i] + 360) % 720 while 1: computeAveLoc() for k in range(20): moveParticle(k) drawParticle(k) g.refresh() turnParticle(k)