Advertisement
here2share

# s60_sparkler

Jul 26th, 2017
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # s60_sparkler
  2. from random import randrange as rnd, random, choice
  3.  
  4. from appuifw import *
  5. from graphics import *
  6. import e32,audio,os,sys,key_codes,time,math,sensor,sysinfo
  7.  
  8. #               R    G    B
  9. WHITE       = (255, 255, 255)
  10. GRAY        = (185, 185, 185)
  11. BLACK       = (  0,   0,   0)
  12. RED         = (155,   0,   0)
  13. GREEN       = (  0, 155,   0)
  14. BLUE        = (  0,   0, 155)
  15. PURPLE      = (128,   0, 128)
  16. YELLOW      = (255, 255,   0)
  17. ORANGE      = (255, 128,   0)
  18.  
  19. bg=GREEN
  20. flare=YELLOW
  21.  
  22. def quit():
  23.     global run
  24.     run=0
  25.  
  26. def draw(rect):
  27.     try: canvas.blit(img)
  28.     except: pass
  29.  
  30. img=None
  31. app.screen='large'
  32. app.orientation='portrait'
  33. app.directional_pad=False
  34. x,y=sysinfo.display_pixels()
  35. img=Image.new((x,y))
  36. app.body=canvas=Canvas(redraw_callback=draw)
  37. app.exit_key_handler=quit
  38.  
  39. Total_x, Total_y=canvas.size
  40. def cv(): pass
  41. cv.x,cv.y = x/2,y/2
  42.  
  43. def up_event(event):
  44.     pass
  45. def dn_event(event):
  46.     cv.x,cv.y=event[0],event[1]-20
  47. def mv_event(event):
  48.     cv.x,cv.y=event[0],event[1]-20
  49. canvas.bind(key_codes.EButton1Up,   up_event, ((0,0), (Total_x,Total_y)))
  50. canvas.bind(key_codes.EButton1Down, dn_event, ((0,0), (Total_x,Total_y)))
  51. canvas.bind(key_codes.EDrag,        mv_event, ((0,0), (Total_x,Total_y)))
  52.  
  53. sprites,obj=100,[]
  54.  
  55. def mv():
  56.     return rnd(0,12)*choice([1,-1])
  57.  
  58. def cycle():
  59.     return [cv.x,cv.y,mv(),mv(),0.5+(random()*5),rnd(20,50)]
  60.  
  61. run=1
  62. while run:
  63.     if len(obj) < sprites: obj.append(cycle())
  64.     img.clear(bg)
  65.     for i in range(len(obj)):
  66.         if obj[i][-1] < 0: obj[i]=cycle()
  67.         obj[i][ 0] += obj[i][ 2]
  68.         obj[i][ 1] += obj[i][ 3]
  69.         obj[i][-1] -= obj[i][-2]
  70.         img.point((int(obj[i][0]),int(obj[i][1])),flare,width=int(obj[i][-1]))
  71.         img.text((30,60),u'Swipe The Screen', fill=WHITE,font=(u'Nokia Hindi S60',40,STYLE_BOLD))
  72.     draw(())
  73.     e32.ao_sleep(0.02)
  74. #
  75.  
  76. '''
  77. e32.ao_yield() # bottom of _running_loop_
  78. app_lock.wait()
  79. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement