Advertisement
here2share

# py60snowfall.py

Nov 29th, 2014
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # py60snowfall.py
  2.  
  3. import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,sensor
  4. import sysinfo
  5.  
  6. yscr=sysinfo.display_pixels()[1]
  7. xscr=sysinfo.display_pixels()[0]
  8. nflakes=240
  9. imgSnow=8
  10. WHITE=0xffffff
  11. LBLUE=0x000080
  12.  
  13. moveX=range(nflakes)
  14. moveY=range(nflakes)
  15. XX=range(nflakes)
  16. YY=range(nflakes)
  17.  
  18. for i in range(nflakes):
  19.     moveY[i]=random.randint(5,20)
  20.     dir=random.choice([-1,1])
  21.     moveX[i]=dir*random.randint(1,3)
  22.     XX[i]=random.randint(0,xscr)
  23.     YY[i]=random.randint(0,yscr)
  24.  
  25. def falling():
  26.     global moveX,moveY,XX,YY
  27.     img.clear(LBLUE)
  28.     for i in range(nflakes):
  29.         dir=random.choice([-1,1])
  30.         moveX[i]=dir*moveX[i]
  31.         XX[i]=XX[i]+moveX[i]
  32.         YY[i]=YY[i]+moveY[i]
  33.         if((XX[i]>xscr)or(XX[i]<0)):
  34.             moveX[i]=-moveX[i]
  35.         if(YY[i]>yscr):
  36.             moveY[i]=random.randint(1,24)
  37.             dir=random.choice([-1,1])
  38.             moveX[i]=dir*random.randint(1,3)
  39.             XX[i]=random.randint(0,xscr)
  40.             YY[i]=dir*random.randint(1,24)
  41.         img.ellipse([(XX[i],YY[i]),(XX[i]+imgSnow,YY[i]+imgSnow)],WHITE,fill=WHITE)
  42.     canvas.blit(img,(0,0))
  43.     timer.after(0.1,falling)
  44.     draw(())
  45.  
  46. def draw(rect):
  47.     try:
  48.         canvas.blit(img)
  49.     except:pass
  50.     appuifw.e32.reset_inactivity()
  51.  
  52. def exit(pos):
  53.     app_lock.signal()
  54.  
  55. img=graphics.Image.new((xscr,yscr))
  56. appuifw.app.directional_pad=False
  57. canvas=appuifw.Canvas(redraw_callback=draw)
  58. appuifw.app.body=canvas
  59. canvas.bind(key_codes.EButton1Down,exit)
  60. appuifw.app.screen='full'
  61.  
  62. timer=appuifw.e32.Ao_timer()
  63. appuifw.app.orientation='portrait'
  64. falling()
  65. e32.ao_yield()
  66.  
  67. app_lock=appuifw.e32.Ao_lock()
  68. app_lock.wait()
  69. timer.cancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement