Advertisement
here2share

#ZZZ bouncing_square.py

Dec 27th, 2014
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # bouncing_square.py <<< ZZZ ? flickers
  2.  
  3. from appuifw import *
  4. import e32
  5. from graphics import *
  6.  
  7. running = 1
  8. def quit():
  9.     global running
  10.     running = 0
  11. app.exit_key_handler = quit
  12.  
  13. def draw(rect):
  14.     try: canvas.blit(img)
  15.     except: pass
  16.  
  17. img = None
  18. app.screen = 'large'
  19. app.orientation = 'portrait'
  20. app.directional_pad = False
  21. app.body = canvas = Canvas(redraw_callback=draw)
  22. img = Image.new(canvas.size)
  23. res_x, res_y = canvas.size
  24.  
  25. dy = 1
  26. dx = 1
  27. x1 = 0
  28. y1 = 0
  29.  
  30. while running:
  31.     x1 = x1 + dx
  32.     y1 = y1 + dy
  33.     x2 = x1 + 100
  34.     y2 = y1 + 100
  35.     if (x1 < -50):
  36.         dx = -1 * dx
  37.     elif (x1 > res_x - 50):
  38.         dx = -1 * dx
  39.     if (y1 < -50):
  40.         dy = -1 * dy
  41.     elif (y1 > res_y - 50):
  42.         dy = -1 * dy
  43.     img.clear(0x000000)
  44.     img.rectangle((x1, y1, x2, y2), fill=0xff0000)
  45.     draw(())
  46.     e32.ao_yield()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement