Commit 22aa3086 authored by Taddeus Kroes's avatar Taddeus Kroes

Added double, single and simple tap to test draw program.

parent c50325c1
...@@ -19,6 +19,13 @@ RECT_COLOR = 0, 200, 0 ...@@ -19,6 +19,13 @@ RECT_COLOR = 0, 200, 0
RECT_POS = W / 2, H / 2 RECT_POS = W / 2, H / 2
RECT_SIZE = W / 6., H / 6. RECT_SIZE = W / 6., H / 6.
TAP_RADIUS = 60
TAP_INCREMENT = .25
BEAM_COLOR = 255, 50, 50
BEAM_LENGTH = 50
BEAM_WIDTH = 3
BEAM_INCREMENT = .8
# Create canvas GUI in the current thread # Create canvas GUI in the current thread
screen = pygame.display.set_mode((W, H)) screen = pygame.display.set_mode((W, H))
...@@ -37,13 +44,15 @@ def coord(x, y): ...@@ -37,13 +44,15 @@ def coord(x, y):
return int(round(W * x)), int(round(H * y)) return int(round(W * x)), int(round(H * y))
# Rotated rectangle # Global state
angle = 0 angle = 0
scale = 1 scale = 1
taps = []
dtaps = []
def update(): def update():
cx, cy = coord(*listener.centroid) global taps, dtaps
# Clear previous frame # Clear previous frame
screen.fill(BG_COLOR) screen.fill(BG_COLOR)
...@@ -57,20 +66,49 @@ def update(): ...@@ -57,20 +66,49 @@ def update():
screen.blit(transformed, rect) screen.blit(transformed, rect)
# Draw touch points # Draw touch points
c = coord(*listener.centroid)
for p in listener.points: for p in listener.points:
x, y = coord(p.x, p.y) xy = coord(p.x, p.y)
# Draw line to centroid # Draw line to centroid
pygame.draw.line(screen, LINE_COLOR, (x, y), (cx, cy), 1) pygame.draw.line(screen, LINE_COLOR, xy, c, 1)
# Draw outlined circle around touch point # Draw outlined circle around touch point
pygame.draw.circle(screen, CIRCLE_COLOR, (x, y), FINGER_RADIUS, 1) pygame.draw.circle(screen, CIRCLE_COLOR, xy, FINGER_RADIUS, 1)
# Fill outlined circle with background color # Fill filled circle with background color within the outline
pygame.draw.circle(screen, BG_COLOR, (x, y), FINGER_RADIUS - 1, 0) pygame.draw.circle(screen, BG_COLOR, xy, FINGER_RADIUS - 1, 0)
# Draw filled circle around centroid # Draw filled circle around centroid
pygame.draw.circle(screen, CIRCLE_COLOR, (cx, cy), CENTROID_RADIUS) pygame.draw.circle(screen, CIRCLE_COLOR, c, CENTROID_RADIUS)
# Draw an expanding circle around each tap event
taps = filter(lambda (xy, r): r <= TAP_RADIUS, taps)
for tap in taps:
xy, radius = tap
pygame.draw.circle(screen, CIRCLE_COLOR, xy, int(radius), 2)
# Increment radius
tap[1] += TAP_INCREMENT
# Shoot a beam from each double tap event to the left
dtaps = filter(lambda (x, y, s): 0 <= x <= W, dtaps)
for dtap in dtaps:
x, y, single = dtap
if single:
start_x = x
end_x = x + BEAM_LENGTH
dtap[0] += BEAM_INCREMENT
else:
start_x = x - BEAM_LENGTH
end_x = x
dtap[0] -= BEAM_INCREMENT
pygame.draw.line(screen, BEAM_COLOR, (start_x, y), (end_x, y), BEAM_WIDTH)
# Update canvas # Update canvas
pygame.display.flip() pygame.display.flip()
...@@ -83,13 +121,16 @@ def rotate(event): ...@@ -83,13 +121,16 @@ def rotate(event):
def pinch(event): def pinch(event):
global scale global scale
scale += event.amount scale *= event.amount
# Start touch event listener in separate thread # Start touch event listener in separate thread
listener = MultiTouchListener(verbose=1, tuio_verbose=0) listener = MultiTouchListener(verbose=1, tuio_verbose=0)
listener.bind('rotate', rotate) listener.bind('rotate', rotate)
listener.bind('pinch', pinch) listener.bind('pinch', pinch)
#listener.bind('tap', lambda e: taps.append([coord(*e.xy), FINGER_RADIUS]))
#listener.bind('single_tap', lambda e: dtaps.append(list(coord(*e.xy)) + [1]))
#listener.bind('double_tap', lambda e: dtaps.append(list(coord(*e.xy)) + [0]))
listener.start(threaded=True) listener.start(threaded=True)
# Start GUI event loop # Start GUI event loop
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment