Advertisement
here2share

# bouncing_sq_RndColors.py

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