Advertisement
here2share

# 360Arrow_pt01.py

Dec 19th, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 360Arrow_pt01.py
  2.  
  3. import e32
  4. import appuifw
  5. import math
  6. import sys
  7. import time
  8. appuifw.app.screen = "normal"
  9. appuifw.app.orientation = "portrait"
  10. exitlock = e32.Ao_lock()
  11. def exit_handler():
  12.     global exit_request
  13.     exit_request = True
  14.     exitlock.signal()
  15. appuifw.app.exit_key_handler = exit_handler
  16.  
  17. arrow_points = [( 0.0, -6.0), ( 3.0,  0.0), ( 1.0,  0.0),
  18.         ( 1.0,  6.0), (-1.0,  6.0), (-1.0,  0.0),
  19.         (-3.0,  0.0)]
  20.  
  21. angle = 0
  22. zoom = 29.0
  23. of_angles = 600
  24.  
  25. def redraw_callback(*args):
  26.     global canvas, angle, zoom
  27.  
  28.     if canvas == None:
  29.         return
  30.  
  31.     # Get center of drawable area.
  32.     xoff = canvas.size[0] / 2
  33.     yoff = canvas.size[1] / 2
  34.  
  35.     # Convert integer angle to radians for math.sin() and math.cos().
  36.     angle_rad = angle * 2 * math.pi / of_angles
  37.  
  38.     # Rotate, scale and transpose points.
  39.     rot_points = []
  40.     for point in arrow_points:
  41.         # Get original point coordinates.
  42.         x, y = point
  43.  
  44.         # Rotate (Can Also Generate A 3D Effect)
  45.         rot_x = math.cos(angle_rad) * x - math.sin(angle_rad) * y
  46.         rot_y = math.sin(angle_rad) * x + math.cos(angle_rad) * y # 0 for horizontal
  47.  
  48.         # Scale
  49.         rot_x *= zoom
  50.         rot_y *= zoom
  51.  
  52.         # Transpose (XY Position of Object)
  53.         rot_x += xoff
  54.         rot_y += yoff
  55.  
  56.         # Append new point coordinates to a list.
  57.         rot_points.append((rot_x, rot_y))
  58.         #print (rot_x, rot_y)
  59.  
  60.     # Draw points as a closed polygon.
  61.     canvas.clear()
  62.     canvas.polygon(rot_points, fill = 0xffff00, outline = 0x000000,
  63.                    width = 2)
  64.  
  65. exit_request = False
  66.  
  67. canvas = None
  68. canvas = appuifw.Canvas(redraw_callback, None, redraw_callback)
  69. appuifw.app.body = canvas
  70.  
  71. # Rotate arrow.
  72. while not exit_request:
  73.     redraw_callback()
  74.     wait=time.time()+0.01 ### moderate speed
  75.     while time.time() < wait:
  76.         e32.ao_yield()
  77.     angle = (angle + 3) % of_angles
  78.     e32.ao_yield() # bottom of _running_loop_
  79.  
  80. exitlock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement