Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multitouch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
multitouch
Commits
22aa3086
Commit
22aa3086
authored
May 08, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added double, single and simple tap to test draw program.
parent
c50325c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
9 deletions
+50
-9
src/draw.py
src/draw.py
+50
-9
No files found.
src/draw.py
View file @
22aa3086
...
...
@@ -19,6 +19,13 @@ RECT_COLOR = 0, 200, 0
RECT_POS
=
W
/
2
,
H
/
2
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
screen
=
pygame
.
display
.
set_mode
((
W
,
H
))
...
...
@@ -37,13 +44,15 @@ def coord(x, y):
return
int
(
round
(
W
*
x
)),
int
(
round
(
H
*
y
))
#
Rotated rectangl
e
#
Global stat
e
angle
=
0
scale
=
1
taps
=
[]
dtaps
=
[]
def
update
():
cx
,
cy
=
coord
(
*
listener
.
centroid
)
global
taps
,
dtaps
# Clear previous frame
screen
.
fill
(
BG_COLOR
)
...
...
@@ -57,20 +66,49 @@ def update():
screen
.
blit
(
transformed
,
rect
)
# Draw touch points
c
=
coord
(
*
listener
.
centroid
)
for
p
in
listener
.
points
:
x
,
y
=
coord
(
p
.
x
,
p
.
y
)
xy
=
coord
(
p
.
x
,
p
.
y
)
# 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
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
pygame
.
draw
.
circle
(
screen
,
BG_COLOR
,
(
x
,
y
)
,
FINGER_RADIUS
-
1
,
0
)
# Fill
filled circle with background color within the outline
pygame
.
draw
.
circle
(
screen
,
BG_COLOR
,
xy
,
FINGER_RADIUS
-
1
,
0
)
# 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
pygame
.
display
.
flip
()
...
...
@@ -83,13 +121,16 @@ def rotate(event):
def
pinch
(
event
):
global
scale
scale
+
=
event
.
amount
scale
*
=
event
.
amount
# Start touch event listener in separate thread
listener
=
MultiTouchListener
(
verbose
=
1
,
tuio_verbose
=
0
)
listener
.
bind
(
'rotate'
,
rotate
)
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
)
# Start GUI event loop
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment