Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 360Arrow_pt01.py
- import e32
- import appuifw
- import math
- import sys
- import time
- appuifw.app.screen = "normal"
- appuifw.app.orientation = "portrait"
- exitlock = e32.Ao_lock()
- def exit_handler():
- global exit_request
- exit_request = True
- exitlock.signal()
- appuifw.app.exit_key_handler = exit_handler
- arrow_points = [( 0.0, -6.0), ( 3.0, 0.0), ( 1.0, 0.0),
- ( 1.0, 6.0), (-1.0, 6.0), (-1.0, 0.0),
- (-3.0, 0.0)]
- angle = 0
- zoom = 29.0
- of_angles = 600
- def redraw_callback(*args):
- global canvas, angle, zoom
- if canvas == None:
- return
- # Get center of drawable area.
- xoff = canvas.size[0] / 2
- yoff = canvas.size[1] / 2
- # Convert integer angle to radians for math.sin() and math.cos().
- angle_rad = angle * 2 * math.pi / of_angles
- # Rotate, scale and transpose points.
- rot_points = []
- for point in arrow_points:
- # Get original point coordinates.
- x, y = point
- # Rotate (Can Also Generate A 3D Effect)
- rot_x = math.cos(angle_rad) * x - math.sin(angle_rad) * y
- rot_y = math.sin(angle_rad) * x + math.cos(angle_rad) * y # 0 for horizontal
- # Scale
- rot_x *= zoom
- rot_y *= zoom
- # Transpose (XY Position of Object)
- rot_x += xoff
- rot_y += yoff
- # Append new point coordinates to a list.
- rot_points.append((rot_x, rot_y))
- #print (rot_x, rot_y)
- # Draw points as a closed polygon.
- canvas.clear()
- canvas.polygon(rot_points, fill = 0xffff00, outline = 0x000000,
- width = 2)
- exit_request = False
- canvas = None
- canvas = appuifw.Canvas(redraw_callback, None, redraw_callback)
- appuifw.app.body = canvas
- # Rotate arrow.
- while not exit_request:
- redraw_callback()
- wait=time.time()+0.01 ### moderate speed
- while time.time() < wait:
- e32.ao_yield()
- angle = (angle + 3) % of_angles
- e32.ao_yield() # bottom of _running_loop_
- exitlock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement