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
a76d047d
Commit
a76d047d
authored
Apr 27, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added visualization program for test/debugging purposes.
parent
ca154c8e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
0 deletions
+108
-0
src/draw.py
src/draw.py
+108
-0
No files found.
src/draw.py
0 → 100644
View file @
a76d047d
#!/usr/bin/env python
import
pygame
,
sys
,
time
from
touch
import
add
,
MultiTouchListener
from
math
import
degrees
,
cos
,
sin
from
events
import
RotateEvent
pygame
.
init
()
# Config
FINGER_RADIUS
=
20
CENTROID_RADIUS
=
15
W
,
H
=
640
,
480
BG_COLOR
=
0
,
0
,
0
LINE_COLOR
=
128
,
128
,
128
CIRCLE_COLOR
=
255
,
255
,
255
RECT_COLOR
=
0
,
200
,
0
RECT_SIZE
=
150
,
100
RECT_POS
=
W
/
2
,
H
/
2
# Create canvas GUI in the current thread
screen
=
pygame
.
display
.
set_mode
((
W
,
H
))
rotations
=
[
RotateEvent
(
W
/
2
,
H
/
2
,
70
,
2
)]
#rotations = []
#x, y, w, h = RECT_SIZE
#rect = [(x, y), (x, y + h), (x + w, y + h), (x + w, y)]
def
rotate_point
(
point
,
axis
,
angle
):
px
,
py
=
point
ax
,
ay
=
axis
x
,
y
=
px
-
ax
,
py
-
ay
radius
=
(
x
*
x
+
y
*
y
)
**
.
5
return
ax
+
radius
*
cos
(
angle
),
ay
+
radius
*
sin
(
angle
)
def
coord
(
x
,
y
):
return
int
(
round
(
W
*
x
)),
int
(
round
(
H
*
y
))
# Rotated rectangle
angle
=
0
scale
=
1
def
update
():
global
rotations
cx
,
cy
=
coord
(
*
listener
.
centroid
)
# Clear previous frame
screen
.
fill
(
BG_COLOR
)
# Apply rotation to rectangle canvas
canvas
=
pygame
.
Surface
((
W
,
H
))
canvas
.
fill
(
BG_COLOR
)
pygame
.
draw
.
rect
(
canvas
,
RECT_COLOR
,
RECT_POS
+
RECT_SIZE
)
scaled_canvas
=
pygame
.
transform
.
scale
(
canvas
,
coord
(
scale
,
scale
))
rotated_canvas
=
pygame
.
transform
.
rotate
(
scaled_canvas
,
degrees
(
angle
))
rect
=
rotated_canvas
.
get_rect
()
rect
.
center
=
W
/
2
,
H
/
2
screen
.
blit
(
rotated_canvas
,
rect
)
# Draw touch points
for
p
in
listener
.
points
:
x
,
y
=
coord
(
p
.
x
,
p
.
y
)
# Draw line to centroid
pygame
.
draw
.
line
(
screen
,
LINE_COLOR
,
(
x
,
y
),
(
cx
,
cy
),
1
)
# Draw outlined circle around touch point
pygame
.
draw
.
circle
(
screen
,
CIRCLE_COLOR
,
(
x
,
y
),
FINGER_RADIUS
,
1
)
# Draw filled circle around centroid
pygame
.
draw
.
circle
(
screen
,
CIRCLE_COLOR
,
(
cx
,
cy
),
CENTROID_RADIUS
)
# Update canvas
pygame
.
display
.
flip
()
def
rotate
(
event
):
global
angle
angle
+=
event
.
angle
def
pinch
(
event
):
global
scale
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
.
start
(
threaded
=
True
)
# Start GUI event loop
try
:
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
:
sys
.
exit
()
update
()
except
KeyboardInterrupt
:
pass
finally
:
print
'Stopping program...'
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